开发者

Google Maps V3 Marker Manager

I am trying to get Marker Manager to work on Google Maps V3. I've tried to replicate what is shown on the tutorial page here, but I cannot seem to get it to work. This is the code I am using so far:

function gmapInit()
    {
        drawMap();
    }

    function drawMap()
    {
        var center = new google.maps.LatLng(..., ...);
        var mapOptions = {
            center: center,
            scrollwheel: false,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            disableDefaultUI: true,
            zoomControl: true,
            streetViewControl: true
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);


        var mgr = new MarkerManager(map);.
   开发者_JAVA百科     google.maps.event.addListener(mgr, 'loaded', function()
        {
            createMarkers(map, mgr);
        });

        map.setCenter(center);
    }

    function createMarkers(map, mgr)
    {
        var bounds = new google.maps.LatLngBounds();

    <c:forEach var="place" items="${places}">
        var point = new google.maps.LatLng(..., ...);    
        bounds.extend(point);    

        var image = new google.maps.MarkerImage("...",               
                new google.maps.Size(25, 25),
                new google.maps.Point(0, 0),
                new google.maps.Point(0, 25),
                new google.maps.Size(25, 25));

        var marker = new google.maps.Marker({
            position: point,
            map: map,
            icon: image
        });

        google.maps.event.addListener(marker, 'click', function()
        {
           ...
        });           

        mgr.addMarker(marker, 20);

    </c:forEach>
        map.fitBounds(bounds);
        mgr.refresh();
        var listener = google.maps.event.addListener(map, "idle", function()
        {
            if (map.getZoom() > 16)
            {
                map.setZoom(16);
            }
        });
    }

However, the icons still keep getting displayed regardless what value I put it and what zoom level I zoom in. Also, I keep getting the following error:

grid is undefined

Any insight on this is appreciated :)

The MarkerManager file I am using can be found here


This seems to have fixed the problem:

 var listener = google.maps.event.addListener(map, "idle", function()
        {
            if (map.getZoom() > 16)
            {
                map.setZoom(16);
            }
            mgr.refresh();
        });

The problem was that the map did not have a zoom level specified.


    var marker = new google.maps.Marker({
        position: point,
        map: map,
        icon: image
    });

    google.maps.event.addListener(marker, 'click', function()
    {
       ...
    });           

    mgr.addMarker(marker, 20);

    you should not assign map to marker while you are adding it to MarkerManager.

    var marker = new google.maps.Marker({
        position: point,
        **// map: map,**
        icon: image
    });

    google.maps.event.addListener(marker, 'click', function()
    {
       ...
    });           

    mgr.addMarker(marker, 20);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜