Skip to content

Instantly share code, notes, and snippets.

@bitsmanent
Last active October 17, 2015 10:07
Show Gist options
  • Select an option

  • Save bitsmanent/c290b8ab6e7963a36fab to your computer and use it in GitHub Desktop.

Select an option

Save bitsmanent/c290b8ab6e7963a36fab to your computer and use it in GitHub Desktop.
Take a string representing a location and returns a formatted political name and coordinates
function strgeo($target) {
$str = rawurlencode($target);
$uri = "http://maps.googleapis.com/maps/api/geocode/json?address=${target}&sensor=true";
$d = json_decode(file_get_contents($uri), 1);
$d = (@$d['results'][0]);
if(!$d)
return NULL;
return [
'targetf' => $d['formatted_address'],
'coords' => $d['geometry']['location'],
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment