Skip to content

Instantly share code, notes, and snippets.

@Cheffheid
Last active September 14, 2016 13:23
Show Gist options
  • Save Cheffheid/b736a7c6789f36f1162243cd8e871e93 to your computer and use it in GitHub Desktop.
Save Cheffheid/b736a7c6789f36f1162243cd8e871e93 to your computer and use it in GitHub Desktop.
Get map coordinates based on City, State cell data
/*
* Uses Google Code built in Maps Geocoder to obtain coordinates for a place in the US, for example: Tucson, AZ
* Usage: On a sheet, select "Tools" -> "Script editor" and paste below (modify output as necessary)
* Then set the value for a blank column to =getCoords(locationCell)
* ie. =getCoords(B2)
* Expected format: City, State
* Format example: Tucson, AZ
*/
function getCoords(value) {
var response = Maps.newGeocoder().geocode(value);
Utilities.sleep(1000);
var coords = response.results[0].geometry.location.lat + ", " + response.results[0].geometry.location.lng;
return coords;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment