Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps "center_changed" is firing my function more than once

Just as the Title implies, I just added a "center_changed" listener to my map and the function is running more than once. I'm assuming it's because the center of the map is changing a bunch of times before the map comes to a rest, but I thought that that's what "drag" was for and that "center_changed only fires once after it comes to a rest??? The only reason I know its firing a bunch of times is because I have a drop shadow on the icon and it gets darker and darker over about two seconds before its completely black. If anyone needs my code, its below.

         google.maps.event.addListener(map, 'center_changed', function() {
    var zoomLevel = map.getZoom();
        if (zoomLevel > 7) {
            clearAll();
            addmarker1();
            addmarker2();
            addmarker3();
            addmarker4();
                    }
        else {
            clearAll();
            }   
            });
like image 522
HondaKillrsx Avatar asked Jul 09 '13 01:07

HondaKillrsx


People also ask

How do I improve Google Maps performance?

Clear app data Google Maps stores data like shared locations, saved locations, and map tiles on your phone or tablet. Clearing this data will do the following things: Delete cache (including search suggestions, direction searches, map tiles, and activity page content stored on your device) Delete cookies.

How do I add an event to Google Maps?

To add an event, head to Google Maps on Android, tap on Contribute >Events > Add a public event. You can add an event name, tag the location, and add the time and date of the event as well. There's an option to add an image, write more event details, and add description as well.

How many markers can be created if maps are generated by the Google wizard?

The use of markers in the map is quite limited but you can put up to 50 markers on a map in 10 different colors and in 3 different sizes with an optional letter in it on the map.


1 Answers

These two functions fire only after your map comes to a rest

If you want your function to execute only when user drags(not programmatically) then use...

       google.maps.event.addListener(map, 'dragend', function(){...}

But if you want your function to execute even when dragged, zoom changed programmatically(e.g. setZoom , fitBounds), then use...

       google.maps.event.addListener(map, 'idle', function(){...}
like image 194
Premshankar Tiwari Avatar answered Oct 13 '22 22:10

Premshankar Tiwari