Created
February 18, 2014 18:22
-
-
Save xeoncross/9076679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
<?php | |
/** | |
* Returns tab-delimited latitude,longitude,formatted address for given address from Google Maps API | |
* @author Warren Stevens (warbaby67@gmail.com) | |
**/ | |
$base = 'http://maps.googleapis.com/maps/api/geocode/json?'; | |
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); | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment