You are here:  » Google Maps API - No parsing results - XML to complex or URL to long?


Google Maps API - No parsing results - XML to complex or URL to long?

Submitted by hmaurich on Thu, 2007-02-22 23:50 in

I work on a Windows 2003 Server with PHP 5.

This works well:
$url = "http://maps.google.com/maps/geo?q=60488%20,%20Frankfurt%20am%20Main&output=xml&key=ABQIAAAA2eOLpCLEO486ddUUJzQI8hShQF2cc6Ht3W7PC_UT09_85ChA6xTkcosAUVb_yfudt2gDZCKf8-mTMg";

If you copy the string an put it in your browser you will get excelent xml.

...but if I trye to get better results with Google Maps - I add my Street an Number - I get with Browser XML, but no Results with MagicParser.

__________________________________

Here is my request URL:

$url =
"http://maps.google.com/maps/geo?q=60488%20Langweidenstra%C3%9Fe%2056,%20Frankfurt%20am%20Main&output=xml&key=ABQIAAAA2eOLpCLEO486ddUUJzQI8hShQF2cc6Ht3W7PC_UT09_85ChA6xTkcosAUVb_yfudt2gDZCKf8-mTMg";

If you put it into the Demo-URL field on this site - no result will appear.

If you copy the xml from browser and put it into the Demo-String field on this site the parser works well.

___________________
___________________
___________________

Now I tryed to make my own programm. First I tryed with url:

$format_string = "xml|kml/Response/Placemark/";
MagicParser_parse($url,"myRecordHandler",$format_string);

...no results, absolutly nothing...no Error

___________________
Than I tryed to parse a string:

$string = http_get($url);
preg_match('/(<\?xml version.*?<\/kml>)/', $string, $kml);
$format_string = "xml|kml/Response/Placemark/";
MagicParser_parse($kml[1],"myRecordHandler",$format_string);

...no results, absolutly nothing...no Error

___________________
At last I tryed to parse a file

$string = http_get($url);
preg_match('/(<\?xml version.*?<\/kml>)/', $string, $kml);
$file = 'tmp/kml.xml';
$fh = fopen($file, 'w');
fwrite($fh, $kml[1]);
fclose ( $fh);
$format_string = "xml|kml/Response/Placemark/";
MagicParser_parse($file,"myRecordHandler",$format_string);

...no results, absolutly nothing...no Error
___________________

...now I don't know how to solve the problem...
Do you know...?

Thanks!!

Submitted by support on Fri, 2007-02-23 09:02

Hi,

Sorry about the problem you are having.

I have been able to recreate the problem, so now I am trying to work out what is going on. I will able to look at this soon and get back to you as soon as possible...

Apologies for the inconvenience;
Cheers,
David.

Submitted by support on Sat, 2007-02-24 12:36

Hi,

This is down to an error in the character encoding of the response XML document in the second URL where the address is used. The XML contains data in the ISO-8859-1 character set, whereas the document is declared as UTF-8.

This causes the parser to abort because it cannot interpret the file correctly if the byte stream does not conform to the declared character set; so this is actually a problem with the original XML, not Magic Parser.

The work around is to read the XML into a string, and then convert it to UTF-8 using the utf8_encode() function. You can then pass the data to MagicParser_parse() using the string:// prefix to get Magic Parser to parse the data directly from memory.

Here's an example code using both of your example Google Maps API URLs:

<?php
  header
("Content-Type: text/plain;charset=UTF-8");
  require(
"MagicParser.php");
  function 
myRecordHandler($record)
  {
    
print_r($record);
  }
  
$url1 "http://maps.google.com/maps/geo?q=60488%20,%20Frankfurt%20am%20Main&output=xml&key=ABQIAAAA2eOLpCLEO486ddUUJzQI8hShQF2cc6Ht3W7PC_UT09_85ChA6xTkcosAUVb_yfudt2gDZCKf8-mTMg";
  
$url2 "http://maps.google.com/maps/geo?q=60488%20Langweidenstra%C3%9Fe%2056,%20Frankfurt%20am%20Main&output=xml&key=ABQIAAAA2eOLpCLEO486ddUUJzQI8hShQF2cc6Ht3W7PC_UT09_85ChA6xTkcosAUVb_yfudt2gDZCKf8-mTMg";
  
$fp fopen($url2,"r");
  
$data "";
  while(!
feof($fp))
  {
    
$data .= fread($fp,1024);
  }
  
fclose($fp);
  
$data utf8_encode($data);
  
MagicParser_parse("string://".$data,"myRecordHandler","xml|KML/");
?>

Hope this helps,
Cheers,
David.

Submitted by hmaurich on Tue, 2007-02-27 17:44

Thank you sooo muche!! It works very well.

Hans-Martin Aurich
Internetservice
www.WebConsultant.de