I created a custom script in Google Sheets using Retrieving location address based on place name and city in Google Spreadsheet. Its is awesome! I wanted to modify the syntax to use the lat long instead of the city and state. I came up with the following:
function mapAddress(SiteName,LatLong) {
var Radius = '100';
var API_KEY = 'XXXXXX';
var url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=' +
SiteName + '&location=' + LatLong + '&radius=' + Radius + '&key=' + API_KEY;
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
obj = JSON.parse(json);
addr = obj.results[0].formatted_address;
return addr;
}
Unfortunately I get an invalid argument in line 6 even though it creates a url that I can post in a browser and get valid results.
Invalid argument:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=BurgerKIng&location= 35.221997,-101.831297&radius=100&key=XXXXXX
(line 6).
I have tried encoding the url but nothing helps. I am a newbie coder but this is about to drive me nuts. Would you be kind enough to help?