Reverse GeoCode Google Sheet

Converting the address to latitude and longitude is known as geocoding. Whereas, converting the latitude and longitude to an address is called reverse geocoding.

Because I am probably not the only person who would like to reverse geocode a dataset, I thought it would be helpful to share my own reverse geocoding process.

Ideally, the dataset would first be in a csv file– with latitude was in one column and longitude in another.

I came across a script that could be used with Google Sheets. It’s on Stack Overflow and called “Get City, State, Country from Latitude and Longitude in Google Sheets. Per the instructions provided by Stack Overflow user Gabriel Rotman, I created a Google Sheet template.

Here is a link to an open, public Google Sheet Template that I created. Feel free to make a copy of it, and then edit it to fit your own needs!

This Google Sheet will provide the address when given the latitude and longitude. The following is the formula: “=reverse_geocode(A1,B1).”

Otherwise, you can copy and paste the script yourself into the ‘<> Script editor’ portion of your Google Sheet (under ‘Tools’). Script is below:

function reverse_geocode(lat,lng) {
Utilities.sleep(1500);

var response = Maps.newGeocoder().reverseGeocode(lat,lng);
for (var i = 0; i < response.results.length; i++) {
var result = response.results[i];
Logger.log('%s: %s, %s', result.formatted_address, result.geometry.location.lat,
result.geometry.location.lng);
return result.formatted_address;
}
}

Again, all credit for the script goes to Stack Overflow user Gabriel Rotman — much thanks to Gabriel!

Cheers!

Japanese Tea
Japanese Tea
Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *