地图没有显示Google Maps API V3 [英] Map doesn't get displayed Google Maps API V3
问题描述
$ b
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代码没有显示任何地图。
我缺少的是什么?
编辑
如下修改V3代码,但仍然没有贴图:
var myOptions = {
zoom:1,
center:chicago,
mapTypeId:google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById(map),myOptions);
确保您载入正确的Google Maps API,你有一个带有地图ID的div标签,并且(为了好的衡量标准)你给div一个高度和宽度。 (也许最好将高度和宽度放在样式表中,但为了清晰起见,我将它包含在内部。)
这是一个包含后期编辑的网页码。尝试一下。适用于我。
< html>
< head>
< title> Google地图测试< /标题>
< script type =text / javascriptsrc =http://maps.google.com/maps/api/js?sensor=false>< / script>
< / head>
< body>
< div id =mapstyle =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>
Code with 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);
}
}
Code with V2 API.
function initialize ()
{
if (GBrowserIsCompatible())
{
map = new GMap2 (document.getElementById("map"));
map.setCenter (new GLatLng(0,0),1 );
}
}
The V2 API code worked flawlessly, the V3 API code is NOt displaying any map. What's the point that I am missing?
EDIT Modified the V3 code as follows, but still no maps:
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);
Make sure you are loading the correct Google Maps API, that you have a div tag with an id of map, and (for good measure) that you give the div a height and width. (Perhaps better to put the height and width in a stylesheet, but for clarity, I'm including it inline here.)
Here's a web page with your post-edit code. Try it. Works for me.
<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 API V3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!