我刚刚从2013年开始使用this video tutorial on youtube作为示例启动json和google maps api。我有要显示的演示地图,但是它给了我一个
您已在此页面上多次添加Google Maps API。这可能会导致意外错误。
原始代码没有api键调用,我添加了,但我想这会调用api两次。我怎么不两次打电话给api?
<head>
<script src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script>
// The web service URL from Drive 'Deploy as web app' dialog.
var DATA_SERVICE_URL = "https://script.google.com/macros/s/SPREADSHEET_ID/exec=?jsonp=callback";
var map;
function initialize() {
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(0, 0),
zoom: 2,
maxZoom: 20,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var scriptElement = document.createElement('script');
scriptElement.src = DATA_SERVICE_URL;
document.getElementsByTagName('head')[0].appendChild(scriptElement);
}
function callback(data) {
for (var i = 0; i < data.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data[i][3], data[i][2]),
map: map
});
}
}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=#######&callback=jsonp"></script>
</head>
答案 0 :(得分:0)
哦,显然不再需要传感器参数,所以我可以
<head>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=#######&callback=jsonp"></script>
<script>
// The web service URL from Drive 'Deploy as web app' dialog.
var DATA_SERVICE_URL = "https://script.google.com/macros/s/SPREADSHEET_ID/exec=?jsonp=callback";
var map;
function initialize() {
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(0, 0),
zoom: 2,
maxZoom: 20,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var scriptElement = document.createElement('script');
scriptElement.src = DATA_SERVICE_URL;
document.getElementsByTagName('head')[0].appendChild(scriptElement);
}
function callback(data) {
for (var i = 0; i < data.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data[i][3], data[i][2]),
map: map
});
}
}
</script>
</head>