Question

I'm converting an application that uses v2 of the google maps api to v3. As part of this I've had to upgrade the MarkerManager to the v3 version too.

I have a bit of an odd issue in that Markers are not showing until the user zooms the map, then they appear.

If I then zoom back to the original zoom level the markers remain, so it is not a min\max zoom issue. There are no errors reported in firebug\javascript console and if I put a breakpoint or console.log at the location where the marker is added, it's definitely being added.

The application is fairly large, so I can't put all the source here, but the code where the markers are added is as follows:

    console.log("Adding Marker");
    markerManager.addMarker(marker, 1, 19);
    markerManager.refresh();

And the code where marker is created is similar to this:

        var latLng = new google.maps.LatLng(y, x);
        var marker = new MarkerWithLabel({
            position: latLng,
            title: "title",
            labelClass: "marker",
            labelContent: "Test",
            icon: icon,
            labelAnchor: new google.maps.Point(26, 32)
        });

and icon is just a google.maps.MarkerImage. MarkerManager and MarkerWithLabel are documented here:

http://google-maps-utility-library-v3.googlecode.com/svn/tags/markermanager/1.0/docs/reference.html

http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.1.7/docs/reference.html

EDIT: I should add that before doing anything with the marker manager after creating it I have the following, so I'm not trying to add anything until it's loaded:

google.maps.event.addListenerOnce(markerManager, 'loaded', function () {

Anybody have any suggestions on where my mistake is likely to be?

Was it helpful?

Solution

I've found a fix for this, though I'm not really sure what other ramifications there might be to this. Basically in markermanager.js I replaced the following (~line 130)

google.maps.event.addListener(map, 'dragend', function () {
    me.onMapMoveEnd_();
});
google.maps.event.addListener(map, 'zoom_changed', function () {
    me.onMapMoveEnd_();
});

with this and the markers appear as expected. I'm still open to other ideas as I'd prefer not to be editing the markermanager file and I'm not sure of the performance (or other) impact of doing this

google.maps.event.addListener(map, 'idle', function () {
    me.onMapMoveEnd_();
});

EDIT: Looking at the markermanager.js dev version, the have all 3 events in there. So it may just be worth using v1.1 if anybody else has this issue:

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markermanager/src/markermanager.js

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top