1
votes

I want to parse this URL with PHP to get the latitude of a specific address (2+bis+avenue+Foch75116+Paris+FR):

I use the google maps web service: http://maps.googleapis.com/maps/api/geocode/json?address=2+bis+avenue+Foch75116+Paris+FR&sensor=false

// Get the JSON 
$url='http://maps.googleapis.com/maps/api/geocode/json?address=2+bis+avenue+Foch75116+Paris+FR&sensor=false';
$source = file_get_contents($url);
$obj = json_decode($source);
var_dump($obj);

It doesn't work. I have this error :

OVER_QUERY_LIMIT

So I searched on the web and I found that there is a limitation using google maps api (Min 1 sec between 2 queries and max 2500 queries per day)

Do you know any way to convert an adress to --> Latitude/Longitude ???

1
Do a var_dump($obj) to see what's in there.Nadh
Do print_r($obj) - what result ?yAnTar
Yes with the var_dump($obj) I understood why I got the previous error. Thank you NADHgeekInside

1 Answers

8
votes

You are accessing results incorrectly.

// Get the JSON 
$url='http://maps.googleapis.com/maps/api/geocode/json?address=2+bis+avenue+Foch75116+Paris+FR&sensor=false';
$source = file_get_contents($url);
$obj = json_decode($source);
$LATITUDE = $obj->results[0]->geometry->location->lat;
echo $LATITUDE;