these bug has been annoying me for a day and I don't even have a clue how it can be fixed. I have a site running for more than a year and there wasn't any problem. Basically when I add new record to the database via a form, it uses geocode from google maps api to get the xml latitude and longitude response and then insert a record into db. But when I tried to do it yesterday it returned error
"Warning: simplexml_load_file() [function.simplexml-load-file]: http://maps.googleapis.com/maps/api/geocode/xml?Key="MY-API-KEY"&address=411+Church+Street++%2C+Parramatta+NSW+2150%2C+Australia&sensor=false:1: parser error : Document is empty in /MY-SITE-DIR/geoCode-1.php on line 40".
While I put the url directly into the browser it returns a perfect xml, that means my url is actually good. I research for whole day long and found some solutions and the following matches my issue most:
This One is to add user agent. But it doesn't work in my case.
Anyone have any suggestion? Following is my relevant code:
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
// Successful geocode
$geocode_pending = false;
$coordinates = $xml->Response->Placemark->Point->coordinates;
$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
$lat = $coordinatesSplit[1];
$lng = $coordinatesSplit[0];
$query = sprintf("UPDATE orthodontist " .
" SET lat = '%s', lng = '%s' " .
" WHERE id = '%s' LIMIT 1;",
mysql_real_escape_string($lat),
mysql_real_escape_string($lng),
mysql_real_escape_string($id));
$update_result = mysql_query($query);
if (!$update_result) {
die("Invalid query: " . mysql_error());
}
}