Retrieving location address based on place name and city in Google Spreadsheet

后端 未结 3 1607
自闭症患者
自闭症患者 2020-12-12 02:07

I\'d like to retrieve a place\'s location based on the name and address in Google Sheets, something like:

=PlaceAddress("White House, Washington, DC"         


        
3条回答
  •  萌比男神i
    2020-12-12 02:34

    Instead of Google Places API you can also use Google Maps Geocoding API. The code from above just needs to be adjusted a bit:

    function mapAddress(address) {
      var API_KEY = 'yourapikeyhere';
      var url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + address + '&lang=en&key=' + API_KEY;
      var response = UrlFetchApp.fetch(url);
      var json = response.getContentText();
      obj = JSON.parse(json);
      addr = obj.results[0].formatted_address;
      return addr;
    }
    

提交回复
热议问题