请找到我在 div 内用于开发 google map 的代码片段。
<?xml version='1.0' encoding='UTF-8'?>
<html>
<body onload="initialize()"><script src="http://www.google.com/jsapi? key=ABCDEFG" type="text/javascript"></script>
<script>
google.load("maps", "2.x");
// Call this function when the page has been loaded
function initialize() {
var map = new google.maps.Map2(document.getElementById("map"));
map.setCenter(new google.maps.LatLng(16.9800, 81.7800), 13);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
}
google.setOnLoadCallback(initialize);
</script>
<form id="f1">
<div id="map" style="width: 400px; height: 400px"></div>
</form>
</body>
</html>
最佳答案
我在 Firefox、Internet Explorer 和 Chrome 中测试了您的脚本,它可以正常工作。
您可能已超出使用配额,或者您可能正在使用未经身份验证的端口。
在开发者控制台(按 F12)中,您可能会看到一条错误,指出:此网站已超出其 Google Maps JavaScript API 的使用配额。有关使用限制的详细信息,请参阅此处:https://developers.google.com/maps/documentation/javascript/usage
如果您没有超出使用限制,则您使用的端口可能未在允许的引荐来源网址列表中列出。引用:https://developers.google.com/maps/documentation/business/places/auth
关于javascript - 谷歌地图5秒后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29789064/