nayen — 2013-03-12T10:31:53-04:00 — #1
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.
cups — 2013-03-12T14:24:59-04:00 — #2
Maybe you have misspelt a key ...
EDIT seems not, but keep adding accessors and see where it goes wrong ...
$data->GeocodeResponse and so on ...
starlion — 2013-03-13T11:06:00-04:00 — #3
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.
nayen — 2013-03-14T04:06:00-04:00 — #4
Thanks, I noticed that shortly after posting this question. I forgot to update here.