Created
February 23, 2016 21:27
-
-
Save luciovilla/49154e08a09ce5a37b40 to your computer and use it in GitHub Desktop.
Geo Location Script for Google Spreadsheet
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
function getLat(address) { | |
if (address == '') { | |
Logger.log("Must provide an address"); | |
return; | |
} | |
var geocoder = Maps.newGeocoder(); | |
var location; | |
// Geocode the address and plug the lat, lng pair into the | |
// 2nd and 3rd elements of the current range row. | |
location = geocoder.geocode(address); | |
// Only change cells if geocoder seems to have gotten a | |
// valid response. | |
if (location.status == 'OK') { | |
lat = location["results"][0]["geometry"]["location"]["lat"]; | |
return lat; | |
} | |
}; | |
function getLon(address) { | |
if (address == '') { | |
Logger.log("Must provide an address"); | |
return; | |
} | |
var geocoder = Maps.newGeocoder(); | |
var location; | |
// Geocode the address and plug the lat, lng pair into the | |
// 2nd and 3rd elements of the current range row. | |
location = geocoder.geocode(address); | |
// Only change cells if geocoder seems to have gotten a | |
// valid response. | |
if (location.status == 'OK') { | |
lng = location["results"][0]["geometry"]["location"]["lng"]; | |
return lng; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment