jjzjj

php - Google Maps V3 Zoom to Show all markers 不工作

coder 2024-04-12 原文

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

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

关于php - Google Maps V3 Zoom to Show all markers 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5999445/

有关php - Google Maps V3 Zoom to Show all markers 不工作的更多相关文章

随机推荐