Created
June 19, 2013 09:52
-
-
Save thomasfr/5813130 to your computer and use it in GitHub Desktop.
Some Google App Script functions. The functions can be used as Google Spreadsheet formulas.
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 geocode(address) { | |
if(address) { | |
var response = Maps.newGeocoder().setRegion('at').geocode(address); | |
var longLat = {}; | |
var l; | |
Logger.log("address: " + address); | |
if (response.status === "OK") { | |
Logger.log("response " + JSON.stringify(response)); | |
if((l = response.results[0].geometry.location)) { | |
longLat.lng = l.lng; | |
longLat.lat = l.lat; | |
return longLat; | |
} | |
} | |
else { | |
return "error"; | |
} | |
} | |
return null; | |
} | |
function showAddress(longLat) { | |
var longLat = longLat.split(','); | |
Logger.log(longLat); | |
var response = Maps.newGeocoder().reverseGeocode(longLat[0], longLat[1]); | |
if(response.status === "OK") { | |
var bestResult = response.results[0]; | |
return bestResult.formatted_address; | |
} | |
return null; | |
} | |
function mapLink(longLat) { | |
if(!longLat) { | |
return null; | |
} | |
return "https://maps.google.at/maps?q="+longLat; | |
} | |
function showCoordinates(address) { | |
if(address) { | |
var longLat = geocode(address); | |
return longLat.lat+","+longLat.lng; | |
} | |
return null; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment