简体   繁体   English

为什么Google地图没有显示?

[英]Why Google Maps doesn't shown?

I got a blue screen when load Google Maps API. 加载Google Maps API时,我出现了蓝屏。 Could you answer if there is any problem with these? 如果这些问题有问题,你能回答吗?

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/

Assuming your page has the element map_canvas , this should work fine. 假设您的页面包含元素map_canvas ,那么应该可以正常工作。 Try posting some HTML and more of your code. 尝试发布一些HTML和更多代码。

Also, try turning off css styles for your page. 另外,请尝试关闭页面的CSS样式。 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还会在页面上设置谷歌地图的样式,因此,例如,如果页面上的所有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). 很可能你的地图集中在尼日利亚西部的一片海(lat:0,lng:0)。 Try zooming the map out and looking around. 尝试缩小地图并环顾四周。

Javascript arrays are zero indexed. Javascript数组是零索引的。 I think 我认为

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]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM