I have a KML with a list of point coordinates of stores with values attached (e.g. weekly revenue). The KML links for every weeks are in a Google Sheet. Each week a new line is added to the Google Sheets with the corresponding weekly data. I have another KML with a polygon - sort of target area. I wanted to run stats on the stores located inside the target area polygon (number of stores, average revenue, etc.) on a weekly basis. I wanted to output those stats on a Google Sheet that I could share for other people to add other data on the stores by hand, and to be able to use the file in the G Suite. Then I wanted all this to update automatically when a new set of weekly data KML is published. I thought I could maybe run all this on Google Apps Script to stay as close as possible to Google Sheets (the way one would do on VBA for Excel). I saw that Google JavaScript API’s geometry library had the containsLocation() function that could help me perform operations on the points within my polygon.
**
**
I tried things like this:
function belongsArea(store, areaCoords) {
var store
var areaCoords
var url = 'https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&callback=belongsFacility';
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
Logger.log(response)
const areaScope = new google.maps.Polygon({ paths: areaCoords });
return google.maps.geometry.poly.containsLocation(store,areaScope)
}
The thing is that I’m not very familiar with JavaScript.
The first issue I encounter is that I always get ReferenceError: google is not defined and I don’t see how to call the API.
Many thanks for your help