gpt4 book ai didi

javascript - Google Maps API 相同示例 : one renders, 一个不

转载 作者:行者123 更新时间:2023-11-28 16:28:18 26 4
gpt4 key购买 nike

这是两个具有相同代码的 jsfiddle。 One是 Google Maps API 文档的分支,没有变化。 The second只是复制并粘贴到 jsfiddle 中。来自 Google 的分支按预期呈现。我复制粘贴的那个没有。

我使用了差异检查器,它显示它们是相同的。我错过了什么?

HTML

<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDglJmtJY5078jjZOJZFNNMO7CJb5E3nE4&callback=initMap">


</script>

JS

// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.

function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 6
});
var infoWindow = new google.maps.InfoWindow({map: map});

// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};

infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}

function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}

CSS

/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}

最佳答案

在您的第二个 fiddle 中,JAVASCRIPT 设置需要将加载类型设置为 No wrap - in <body>

关于javascript - Google Maps API 相同示例 : one renders, 一个不,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40857372/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com