Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get long/lat for a given address in Google Maps with only PHP?

I know this is possible in Javascript but I need to do it using only PHP, how can I?

like image 886
Andrew G. Johnson Avatar asked Oct 06 '09 14:10

Andrew G. Johnson


People also ask

Is Google geocoding API free?

The Geocoding API uses a pay-as-you-go pricing model. Geocoding API requests generate calls to one of two SKUs depending on the type of request: basic or advanced. Along with the overall Google Terms of Use, there are usage limits specific to the Geocoding API.


2 Answers

Yes, there's a HTTP geocoding interface that you can call from any server language.

like image 113
Mike Williams Avatar answered Oct 12 '22 13:10

Mike Williams


And other way:

$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$address.'&sensor=false');

$output= json_decode($geocode);

$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
like image 33
Tizón Avatar answered Oct 12 '22 13:10

Tizón