I would like to know how to retrieve an address based on name and city of a place in Google Sheets? I have read the answer to this question and followed the instructions, but the code from the answer in that post generated the following error for me:
TypeError: Cannot read property "formatted_address" from undefined. (line 8, file "Code")
Going to the linked question above will show you the code in the answer, but here is the short version:
After obtaining a key for the Google Places API, enter the user defined formula in any cell in Google Sheets as follows:
=mapAddress(B1, B2, B3)
In the text editor, copy and paste:
function mapAddress(place, city, state) {
var API_KEY = 'yourapikeyhere';
var url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=' +
place + ' ' + city + ' ' + state + '&key=' + API_KEY;
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
obj = JSON.parse(json);
addr = obj.results[0].formatted_address;
return addr;
}
I do not have a high enough score to post comments on that question, which is why I must ask a new question. Is there a Google Sheets template or add-in that achieves this?