开发者

Google maps KM bounds box reapplying itself on map zoom

I have a map in which I apply a custom overlay using KMbox overlay to signify where I think the users general point of interest lies. What I want is to display this map to the user and allow them to click on the map to give开发者_如何学运维 me an exact location match of their POI.

This all works fine except for when the user clicks on the map and changes the zoom of the map.

Here's my code to add the marker to the map.

 function addMarker(location) {

        if(KmOverlay)
        {
            KmOverlay.remove();
        }
        if(last_marker)
        {
            last_marker.setMap(null);
        }

        marker = new google.maps.Marker({
            position: location,
            map: map
        });

        // Keep track for future unsetting...
       last_marker = marker;     
    }

And to show the map I have this function.

function show_map(lt, ln, zoom, controls, marker) 
{
    var ltln = new google.maps.LatLng(lt, ln);
    var vars = {
        zoom: zoom,
        center: ltln,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        navigationControl: controls,
        navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN} ,
        mapTypeControl: false,
        scaleControl: false,
        scrollwheel: false
    };

    map = new google.maps.Map(document.getElementById("map_canvas"), vars);

    KmOverlay = new KmBox(map, new google.maps.LatLng(lat, lon), KmOpts);
    var totalBounds = new google.maps.LatLngBounds();
    totalBounds.union(KmOverlay.getBounds());


    google.maps.event.addListener(map, 'click', function(event) {
        addMarker(event.latLng);
    });

}

I have a working example at the following link here


fixed this by using the setMap() method on the KmOverlay and passing null as a parameter.

eg:

function addMarker(location) {

    if(KmOverlay)
    {
        KmOverlay.setMap(null);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜