Showing errors while creating Google Maps URL from a Sheets using App Scripts?

喜夏-厌秋 提交于 2021-02-05 08:38:46

问题


I have latitude and longitude values in a Google Sheet and I want to draw a Google Map URL using App Scripts. I have a paid Google Maps API key but can't find ways to integrate it with my App Scripts code in the Script Editor?

While executing the codes, it shows error message,

"The Google Maps Platform server rejected your request. You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account"

The codes are as follows:

    function mappingLoc() {
        var spreadsheet = SpreadsheetApp.getActive();
        var dashboard = spreadsheet.getSheetByName('Dashboard');
        var tempdataset = spreadsheet.getSheetByName('TempDataSet');
    
        var data = tempdataset.getLastRow();
        var latis = [];
        var latis = tempdataset.getRange(2, 4, data).getValues();  
    
        var longis = [];
        var longis = tempdataset.getRange(2, 5, data).getValues();        
          
        //var map = Maps.newStaticMap().addMarker(latis, longis);
        var map=latis.reduce((map,[lat],i)=>map.addMarker(Number(lat),Number(longis[i][0])),Maps.newStaticMap());
        dashboard.getRange("A71").setValue(map.getMapUrl());          
     }

回答1:


The free usage of the Static Maps API has limits

See here:

There is also a lmit for Maximum Queries per Second (QPS): 500

In other words:

If you perform more than 100 000 requests per month or more than 500 requests per second you will be required to pay.

If you are interested: Here you can find information about how to set-up a billing account and obtaining an API key for the paid service.

Alternatively:

Reduce the total amount of your requests and especially the request speed to keep using the Static Maps API for free.



来源:https://stackoverflow.com/questions/64040083/showing-errors-while-creating-google-maps-url-from-a-sheets-using-app-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!