I got a blue screen when load Google Maps API. Could you answer if there is any problem with these?
加载Google Maps API时,我出现了蓝屏。如果这些问题有问题,你能回答吗?
Alert message result: http://img829.imageshack.us/img829/9279/soru1k.jpg
提示信息结果:http://img829.imageshack.us/img829/9279/soru1k.jpg
Initialize function:
初始化功能:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function yukle() {
var locations = $.parseJSON({$json});
alert(locations[0]);
var latlng = new google.maps.LatLng(locations[0][1], locations[0][2]);
var myOptions = {
zoom: 7,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
}
</script>
HTML:
HTML:
<div id="map_canvas" style="width:620px; height:470px"></div>
CSS:
CSS:
<style type="text/css">
#map_canvas {
height: 100%;
}
</style>
The result is a blue screen on map: http://imageshack.us/photo/my-images/546/soru3.jpg/
结果是地图上的蓝屏:http://imageshack.us/photo/my-images/546/soru3.jpg/
2 个解决方案
#1
0
Javascript arrays are zero indexed. I think
Javascript数组是零索引的。我认为
var latlng = new google.maps.LatLng(locations[0][1], locations[0][2]);
Should be
应该
var latlng = new google.maps.LatLng(locations[0][0], locations[0][1]);
#2
3
Assuming your page has the element map_canvas
, this should work fine. Try posting some HTML and more of your code.
假设您的页面具有元素map_canvas,这应该可以正常工作。尝试发布一些HTML和更多代码。
Also, try turning off css styles for your page. your css will also style the google map things on your page, so if, for instance, all the div
on your page are solid blue it might affect the google map elements.
另外,请尝试关闭页面的CSS样式。你的CSS也会在页面上设置谷歌地图的样式,所以如果你的页面上的所有div都是纯蓝色,那么它可能会影响谷歌地图元素。
EDIT:
编辑:
With the screenshot you've given, its pretty clear the map is rendering correctly. There is something wrong with the line:
通过您给出的屏幕截图,非常清晰的地图正确渲染。该行有问题:
var latlng = new google.maps.LatLng(locations[0][1], locations[0][2]);
In particular, the latlng isn't correctly being made, or the coordinates are wrong. It's likely that your map is focused on a patch of sea slightly west of Nigeria (lat:0,lng:0). Try zooming the map out and looking around.
特别是,没有正确地制作latlng,或者坐标是错误的。很可能你的地图集中在尼日利亚西部的一片海(lat:0,lng:0)。尝试缩小地图并环顾四周。
#1
0
Javascript arrays are zero indexed. I think
Javascript数组是零索引的。我认为
var latlng = new google.maps.LatLng(locations[0][1], locations[0][2]);
Should be
应该
var latlng = new google.maps.LatLng(locations[0][0], locations[0][1]);
#2
3
Assuming your page has the element map_canvas
, this should work fine. Try posting some HTML and more of your code.
假设您的页面具有元素map_canvas,这应该可以正常工作。尝试发布一些HTML和更多代码。
Also, try turning off css styles for your page. your css will also style the google map things on your page, so if, for instance, all the div
on your page are solid blue it might affect the google map elements.
另外,请尝试关闭页面的CSS样式。你的CSS也会在页面上设置谷歌地图的样式,所以如果你的页面上的所有div都是纯蓝色,那么它可能会影响谷歌地图元素。
EDIT:
编辑:
With the screenshot you've given, its pretty clear the map is rendering correctly. There is something wrong with the line:
通过您给出的屏幕截图,非常清晰的地图正确渲染。该行有问题:
var latlng = new google.maps.LatLng(locations[0][1], locations[0][2]);
In particular, the latlng isn't correctly being made, or the coordinates are wrong. It's likely that your map is focused on a patch of sea slightly west of Nigeria (lat:0,lng:0). Try zooming the map out and looking around.
特别是,没有正确地制作latlng,或者坐标是错误的。很可能你的地图集中在尼日利亚西部的一片海(lat:0,lng:0)。尝试缩小地图并环顾四周。