Google地图会显示错误信息而不是地图

时间:2011-03-02 21:11:47

标签: javascript google-maps

我想在我的项目中添加一个带有一些自定义标记的地图。在localhost上一切正常但是当我将代码发送到生产服务器时,我得到了“抱歉,我们没有所需规模的这个区域的地图”(或类似的东西)。这是代码:

<script type='text/javascript'>
    var map;
    var mapStart = function(){
        if(GBrowserIsCompatible()){
            map = new GMap2(document.getElementById("map"));
            map.setCenter(new GLatLng(51.961869,19.134521),6);
            map.addControl(new GLargeMapControl());
            var ikona1 = new GIcon();
            ikona1.image = "{{MEDIA_URL}}images/map_icon_1.png";
            ikona1.iconSize = new GSize(36, 30);
            ikona1.infoWindowAnchor = new GPoint(16,16);
            ikona1.iconAnchor = new GPoint(16,16);
            var data_map = {{ properties|safe }}       
            map.enableDoubleClickZoom();
            map.enableContinuousZoom();
            var bounds = new GLatLngBounds();
            var maxlng =0;
            var maxlat=0;
            var minlng=0;
            var minlat=0;
            for (var i=0; i < data_map.length; i++){
                var pos_lat = parseFloat(data_map[i]['lat']);
                var pos_lon = parseFloat(data_map[i]['long']);
                addMarker(pos_lat, pos_lon,{icon:ikona1}, data_map[i]['info_box']
                );
                if (pos_lat < minlat || minlat==0){ minlat = pos_lat}
                if (pos_lat > maxlat || maxlat==0){ maxlat = pos_lat}
                if (pos_lon < minlng || minlng==0){minlng = pos_lon}
                    if (pos_lon > maxlng || maxlng==0){maxlng = pos_lon}
                lat = minlat + (( maxlat - minlat)/2);
                lng = minlng + (( maxlng - minlng)/2);
                var allpoints = new GLatLng(lat,lng);
                bounds.extend(allpoints);
            }
            map.setZoom(map.getBoundsZoomLevel(bounds)-2);
            map.setCenter(bounds.getCenter());
        }
    }

    var addMarker = function(lat, lon, options, info_box_html){
        point = new GLatLng(lat,lon);
        var marker = new GMarker(point, options);

        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(info_box_html);
        });

        map.addOverlay(marker);
    }

    $(document).ready(function(){
        mapStart();
    });   
    window.onunload = function (){ GUnload()};
</script>

我有以下导入(生成新密钥):

<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAA2YOYLBVnylQ7NK445E1_gxQFK8hZs27CqIA3jAe_qRgIGP9GQBTFZjebH-xe-6vEjhK0Pa9agV_Mpg"></script>

data_map具有正确的格式,因为我已在本地测试过它。此外,当我评论出创建地图和添加控件的所有内容时,我得到了清晰的灰色屏幕任何人都知道这个错误?

1 个答案:

答案 0 :(得分:0)

你有有效的坐标。我想知道你是否发送map.setZoom有效值。如果不设置缩放级别会发生什么?