How to get Longitude and Latitude from Address using PHP

03 May

Couple of days ago I have worked with Google Map to do search pharmacy. Basically requirement is, user will search with zip code and the result will display all the pharmacy with a certain radius of the zip code. After doing some research I found, this can be search with with latitude and longitude (I won’t discus about this today, I will write about this in another post). Entering latitude and longitude by the user won’t be a smart application, so I plan to get the latitude an longitude from the given address.

Google provide example to identify latitude and longitude from address with JavaScript. But I need it from PHP code. After spending some time on Google I found the solution 🙂

Here I am going to find latitude and longitude of my current office


$output= json_decode($jsondata);

$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[0]->geometry->location->lng;

echo “Latitude : “.$lat;
echo “Longitude : “.$long;

My example for JSON data. To get XML data, you just need to use xml instead of json. Do not use any space in address parameter, just use plus (+) sign here.

For more details visit this page The Google Geocoding API

Leave a comment

Posted by on May 3, 2012 in Uncategorized


Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: