English 中文(简体)
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);
    }
问题回答

暂无回答




相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签