0

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());
  }
} 

1 Answer 1

1

API V2 has stopped working a couple of days ago. I can see by your code, you are using API V2.

You need to use API v3 Here is an example of PHP code to use with v3

www.fcsoftware.co.uk/blog/?p=66

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.