Microsoft Developer Network >
Forums Home
>
Windows Live Developer Forums Forums
>
Multimap API Development Forum
>
Intermittent problem getting XML lat/lon
Intermittent problem getting XML lat/lon
- Hi,
I have a problem with Geocode! I have been getting the lat/lon from your XML files based on postcode. My map has been online and working fine for about a year now. The other week I discovered that the the PHP code had stopped working which I was using to get the lat and lon from your XML files, although it still worked for me from a web browser...
http://developer.multimap.com/API/geocode/1.2/[api key]?qs=[postcode]
My own XML file, which was been automatically populated with the lat/lon by a cron job, was suddenly coming up with blanks for lat and lon. I hadn't made any changes to my code.
Anyway, I thought I'd create a simple test file to try to see what was happening (see below) so I did that, and couldn't find the problem, so I gave up for a while... then I tried my test file a few days later aiming to really spend some time delving in to the problem.... and it was magically working again, and echoing the latitute and longitute in my array perfectly!
BUT, i've noticed again today that the lat and lon's have disappeared again, so i went back to my test file (still the same one!) and it had stopped working again.
I just wondered if you had any ideas what the problem could be? Could you run this file and see if it works for you? Has there been an intermittent problem on the XML geocode or has somthing changed recently (and changed back again, then changed back)? Could I be making too many requests or something? would it help if i gave you my API key?
Many thanks indeed,
Kind regards,
Jen
<?php class xml_story{ var $lat, $lon; } function startTag($parser, $data){ global $current_tag; $current_tag .= "*$data"; } function endTag($parser, $data){ global $current_tag; $tag_key = strrpos($current_tag, '*'); $current_tag = substr($current_tag, 0, $tag_key); } function contents($parser, $data){ global $current_tag, $xml_lat_key, $xml_lon_key, $counter, $story_array; switch($current_tag){ case $xml_lat_key: $story_array[$counter] = new xml_story(); $story_array[$counter]->lat = $data; break; case $xml_lon_key: $story_array[$counter]->lon = $data; $counter++; break; } } $xml_file = "http://developer.multimap.com/API/geocode/1.2/[api key]?qs=SY208NR" . str_replace(' ', '',$location ); $xml_lat_key = "*RESULTS*LOCATION*POINT*LAT"; $xml_lon_key = "*RESULTS*LOCATION*POINT*LON"; $story_array = array(); $counter = 0; $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startTag", "endTag"); xml_set_character_data_handler($xml_parser, "contents"); $fp = fopen($xml_file, "rb") or die("Could not open file"); $data = stream_get_contents($fp) ; if(!(xml_parse($xml_parser, $data, feof($fp)))){ die("Error on line " . xml_get_current_line_number($xml_parser)); } xml_parser_free($xml_parser); fclose($fp); for($x=0;$x<count($story_array);$x++){ $lat = $story_array[$x]->lat; $lon = $story_array[$x]->lon; } echo $xml_file; echo '<br/>'; print_r($story_array); ?>
Answers
I appreciate that it's just a simple example, but you don't seem to be checking for any error response.
http://www.multimap.com/openapidocs/1.2/web_service/ws_geocoding.htm#error
MM may be telling you what the problem is, but you need to get the code not just hope lat/long is always present.
cheers, Ross K- Marked As Answer byJohn-SheridanMSFT, ModeratorWednesday, November 11, 2009 11:02 AM
All Replies
I appreciate that it's just a simple example, but you don't seem to be checking for any error response.
http://www.multimap.com/openapidocs/1.2/web_service/ws_geocoding.htm#error
MM may be telling you what the problem is, but you need to get the code not just hope lat/long is always present.
cheers, Ross K- Marked As Answer byJohn-SheridanMSFT, ModeratorWednesday, November 11, 2009 11:02 AM

