谷歌地图api缩放不起作用

时间:2015-06-09 09:04:45

标签: google-maps-api-3

我有缩放问题。我试着谷歌,但似乎我坚持这个。

如果我在缩放参数中调整设置,则无效! 这是我的代码中的错误,还是我错过了她的一些东西?

任何帮助/提示都将不胜感激!

var markers = [
    <?php include("gmaps/hyttetomter.php"); ?>
    <?php include("gmaps/boligtomter.php"); ?>
 ,    ];
window.onload = function () {

    var mapOptions = {
        panControl: true,
        streetViewControl: false,
        panControlOptions: {
            position: google.maps.ControlPosition.TOP_LEFT
        },
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
            position: google.maps.ControlPosition.TOP_RIGHT
        },
        center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var infoWindow = new google.maps.InfoWindow();

    var imageBounds = new google.maps.LatLngBounds(
        new google.maps.LatLng(58.608394, 7.940108),
        new google.maps.LatLng(58.996358, 8.781880)
    );

    var latlngbounds = new google.maps.LatLngBounds();
    var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
    var i = 0;

    var interval = setInterval(function () {
        var data = markers[i]
        var myLatlng = new google.maps.LatLng(data.lat, data.lng);
        var icon = "";
        switch (data.type) {
            case "Hyttefelt":
                icon = "red";
                break;
            case "Boligfelt":
                icon = "yellow";
                break;
            case "Hyttetomt":
                icon = "blue";
                break;
            case "Boligtomt":
                icon = "green";
                break;
        }
        icon = "http://maps.google.com/mapfiles/ms/icons/" + icon + ".png";
        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title: data.title,
            animation: google.maps.Animation.DROP,
            icon: new google.maps.MarkerImage(icon)
        });

        (function (marker, data) {
            google.maps.event.addListener(marker, "click", function (e) {
                window.location.href = data.description;
            });
        })(marker, data); 

        latlngbounds.extend(marker.position);
        i++;

        if (i == markers.length) {
            clearInterval(interval);
            map.setCenter(latlngbounds.getCenter());
            map.fitBounds(latlngbounds);
        }   
        historicalOverlay = new google.maps.GroundOverlay(
            'images/map/kart-amli.png',
            imageBounds
        );
        historicalOverlay.setMap(map);
    }, 80); 
}

2 个答案:

答案 0 :(得分:0)

这可能没有用,但这是代码,它对我有用,也许你必须将它全部放入一个变量,就像我有

var mapOptions = {
        zoom: 2,
        center: myLatlng
    } 

答案 1 :(得分:0)

我找到了! map.fitBounds(bounds);会超越缩放功能。

谢谢!

相关问题