Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/php -q
* Returns tab-delimited latitude,longitude,formatted address for given address from Google Maps API
* @author Warren Stevens (
$base = '';
if (count($argv) < 2)
print "usage: ".__FILE__." \"<city,state>\"\n";
exit(64); # Command line usage error
$result = json_decode(file_get_contents($base.'address='.urlencode($argv[1]).'&sensor=false'),true);
if ($result['status'] == 'ZERO_RESULTS' || count($result['results']) == 0)
print 'No results for "'.$argv[1].'"'."\n";
exit(65); # Data format error
$lat = $result['results'][0]['geometry']['location']['lat'];
$lng = $result['results'][0]['geometry']['location']['lat'];
$add = $result['results'][0]['formatted_address'];
print sprintf("%s\t%s\t%s\n", $lat,$lng,$add);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.