I am trying to convert an address to coordinates using the following but it doesn't work (no errors displayed):
$data = new SimpleXMLElement(file_get_contents('http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false'));
$latitude = $data->GeocodeResponse->result->geometry->location->lat;
$longitude = $data->GeocodeResponse->result->geometry->location->lng;
I guess I am doing something wrong but I can't see what.
Thanks for any ideas.
Maybe you have misspelt a key ...
EDIT seems not, but keep adding accessors and see where it goes wrong ...
$data->GeocodeResponse and so on ...
XML parsing strips off the first element of the return as the base container. $data is already pointing at the GeocodeResponse.
$latitude = $data->result->geometry->location->lat;
will get you your value.
Thanks, I noticed that shortly after posting this question. I forgot to update here.
This topic is now closed. New replies are no longer allowed.