gpt4 book ai didi

google-maps - 无法显示 map Google Maps API V3

转载 作者:行者123 更新时间:2023-12-04 13:24:40 25 4
gpt4 key购买 nike

使用V3 API进行编码。

function initialize ()
{
if (GBrowserIsCompatible())
{
var ch = new GLatLng (0,0);

var myOptions = {
zoom:7,
center: ch,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

map = new google.maps.Map(document.getElementById("map"), myOptions);

directionsDisplay = new google.maps.DirectionsRenderer(map, document.getElementById("map"));
directionsDisplay.setMap(map);
}
}

使用V2 API进行编码。

function initialize ()
{
if (GBrowserIsCompatible())
{
map = new GMap2 (document.getElementById("map"));
map.setCenter (new GLatLng(0,0),1 );
}
}

V2 API代码可以完美地工作,V3 API代码不会显示任何 map 。
我想念的重点是什么?

编辑
修改了V3代码,如下所示,但仍然没有 map :

var chicago = new google.maps.LatLng (0, 0);

var myOptions = {
zoom:1,
center: chicago,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

map = new google.maps.Map(document.getElementById("map"), myOptions);

最佳答案

确保您加载的是正确的Google Maps API,具有带有 map ID的div标签,并且(为了很好地确保)为div设置了高度和宽度。 (将高度和宽度放在样式表中可能更好,但是为了清楚起见,我在此处内嵌了它。)

这是一个包含您的后期编辑代码的网页。试试吧。为我工作。

<html>
<head>
<title>Google Map test</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>
<body>
<div id="map" style="height:500px;width:500px"></div>
<script>
var chicago = new google.maps.LatLng (0, 0);

var myOptions = {
zoom:1,
center: chicago,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

map = new google.maps.Map(document.getElementById("map"), myOptions);
</script>
</body>
</html>

关于google-maps - 无法显示 map Google Maps API V3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6176622/

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