为何Google地图无法显示?

时间:2011-10-24 12:12:06

标签: php javascript google-maps

加载Google Maps API后,我出现了蓝屏。如果这些问题有问题,你能回答吗?

警报讯息结果: http://img829.imageshack.us/img829/9279/soru1k.jpg

初始化功能:

            <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:

<div id="map_canvas" style="width:620px; height:470px"></div>

CSS:

    <style type="text/css">
        #map_canvas {
        height: 100%;
        }
    </style>

结果是地图上的蓝屏: http://imageshack.us/photo/my-images/546/soru3.jpg/

2 个答案:

答案 0 :(得分:3)

假设您的网页包含元素map_canvas,这应该可以正常工作。尝试发布一些HTML和更多代码。

另外,请尝试关闭页面的CSS样式。你的CSS还会在页面上设置谷歌地图的样式,例如,如果页面上的所有div都是纯蓝色,则可能会影响谷歌地图元素。

编辑:

使用您提供的屏幕截图,非常清楚地图正确渲染。这条线有问题:

var latlng = new google.maps.LatLng(locations[0][1], locations[0][2]);

特别是,没有正确制作latlng,或者坐标错误。很可能你的地图集中在尼日利亚西部的一片海(lat:0,lng:0)。尝试缩小地图并环顾四周。

答案 1 :(得分:0)

Javascript数组是零索引的。我想

var latlng = new google.maps.LatLng(locations[0][1], locations[0][2]);

应该是

var latlng = new google.maps.LatLng(locations[0][0], locations[0][1]);
相关问题