Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

Getting an API error when trying to launch a static google map

  1. I am trying to execute a static map from a cell on a google sheet via a google script. My end goal is to load my own map (contained in a .kmz that was downloaded from google my maps) and display a pin to locate a user-defined zone (colored polygon on map).

I have an API key already set up from previous mapping tasks.

function getZone() {
  var app = SpreadsheetApp;

  var ss = app.getActiveSpreadsheet().getActiveSheet();

  var address = ss.getRange("A1").getValue();

  var testMap = Maps.newStaticMap().addMarker(address);

  ss.getRange("B1").setValue(testMap.getMapUrl());
}

I then receive this error when I click on the link in my spreadsheet:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

That error means you need to append the API key to the static map URL.

it should be the existing URL +"&key="+YOUR_API_KEY

The final URL should be (for your example):

http://maps.google.com/maps/api/staticmap?sensor=false&size=512x512&markers=131+Broadview+Avenue+Warrenton+VA&key=YOUR_API_KEY) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...