Home

How to geocode an address using Google and php

by jeremy

Google has some amazing services, one of my favourites would have to be the ability to geocode an address and get not only the lat/long but a clean, well formatted address back. 

How you say... Easy!

Get yourself an api key from here: http://code.google.com/apis/maps/signup.html

use the following php code:

<?php
$key
//your api key
$address //address to geocode

$url = 'http://maps.google.com/maps/geo?q='.urlencode($address).'&output=json&sensor=false&key='.$key;
$data = file_get_contents($url);           
$loc = json_decode($data);
$lat = $loc->Placemark[0]->Point->coordinates[0];
$long = $loc->Placemark[0]->Point->coordinates[1];
?>

Thanks Google!

January14

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
8 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.