I have a simple function that converts address string into longitude and latitude using simple XML from Google. I get this weird warning error once in a while:
Warning: simplexml_load_file(http://maps.googleapis.com/maps/api/geocode/xml?address=&sensor=true): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /search_results.php on line 193
Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://maps.googleapis.com/maps/api/geocode/xml?address=&sensor=true" in /search_results.php on line 193 url not loading
Is there a better way to do this to avoid this error?
My code is below:
$geo_address = urlencode($address);
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$geo_address."&sensor=true";
$xml = simplexml_load_file($request_url) or die ("url not loading");
$status = $xml->status;
if ($status=="OK") {
$lat = $xml->result->geometry->location->lat;
$lon = $xml->result->geometry->location->lng;
}