0

我有一张地图,在其中我使用KMbox叠加应用自定义叠加来表示我认为用户的一般兴趣点所在的位置。我想要的是向用户显示这张地图,并允许他们点击地图给我他们的 POI 的精确位置匹配。

这一切都很好,除了当用户点击地图并改变地图的缩放比例。

这是我将标记添加到地图的代码。

 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;     
    }

为了显示地图,我有这个功能。

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

}

我在以下链接中有一个工作示例

4

1 回答 1

0

通过在 KmOverlay 上使用 setMap() 方法并将 null 作为参数传递来解决此问题。

例如:

function addMarker(location) {

    if(KmOverlay)
    {
        KmOverlay.setMap(null);
    }
于 2010-05-31T10:19:33.230 回答