-1

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?

Community
  • 1
  • 1
mingo3369
  • 1
  • 1

2 Answers2

0

For posterity and to close the question: you noted in a comment that there was a space in the source data, resulting in a space after the = in the URL. Removing this resolved the issue.

Max Ghenis
  • 14,783
  • 16
  • 84
  • 132
0

The answer was "could it be theres a space in location= 35.." as I mentioned in my comment. You can accept this as the answer for others to see.

Hassan
  • 301
  • 1
  • 13