php – 谷歌地图V3缩放显示所有标记不起作用

我正在使用Google Maps V3 API,在地图上创建了几个标记之后,我很难让地图缩小以显示所有标记.现在,下面的代码显示标记而不调整缩放.你能在那里找到错误吗?谢谢!

<script type="text/javascript">
    function initialize() {
        var latlng = new google.maps.LatLng(1.289566,103.847267);
        var options = {  
            zoom: 15,  
            center: latlng,  
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            scrollwheel: false
        }; 

        var map = new google.maps.Map(document.getElementById('map_canvas'), options);  
        var marker = new google.maps.Marker({  
            position: new google.maps.LatLng(1.289566,103.847267),
            map: map,
            icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=1|ff776b"
        }); 

        var marker = new google.maps.Marker({  
            position: new google.maps.LatLng(1.301224,103.912949),
            map: map,
            icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=2|ff776b"
        }); 

        var marker = new google.maps.Marker({  
            position: new google.maps.LatLng(1.293150,103.827164),
            map: map,
            icon: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=3|ff776b"
        }); 

        var LatLngList = array (
        new google.maps.LatLng(1.289566,103.847267),
        new google.maps.LatLng(1.301224,103.912949),
        new google.maps.LatLng(1.293150,103.827164)
        );

        var bounds = new google.maps.LatLngBounds();

        for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) {
            bounds.extend(LatLngList[i]);
        }

        map.fitBounds(bounds);

    }
</script>

解决方法:

这个:

var LatLngList = array (
        new google.maps.LatLng(1.289566,103.847267),
        new google.maps.LatLng(1.301224,103.912949),
        new google.maps.LatLng(1.293150,103.827164)
        );

不是你在JavaScript中创建数组的方式.相反,尝试:

var LatLngList = [
    new google.maps.LatLng(1.289566,103.847267),
    new google.maps.LatLng(1.301224,103.912949),
    new google.maps.LatLng(1.293150,103.827164)
    ];

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...