Skip to content

Instantly share code, notes, and snippets.

@kenmickles
Created March 1, 2012 15:35
Show Gist options
  • Save kenmickles/1950555 to your computer and use it in GitHub Desktop.
Save kenmickles/1950555 to your computer and use it in GitHub Desktop.
Simple PHP geocode function
function geocode($address) {
$url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&sensor=false';
$response = json_decode(file_get_contents($url), 1);
if ( isset($response['results'][0]) ) {
$ll = $response['results'][0]['geometry']['location'];
return array($ll['lat'], $ll['lng']);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment