alexander-fire
alexander-fire

Reputation: 1082

Dynamically add markers on changed map - Google Maps API

I have a google map with markers where the retail locations are.

It works fine.

If the user change the map focus by drag and drop (change the map extract) I want to add dynamically new markers if in this map extract is a shop.

I have no idea, where I find such a example or something else.

Upvotes: 1

Views: 4400

Answers (1)

GEMI
GEMI

Reputation: 2279

First of all you need to load the initial batch of markers and then listen for the "bounds_changed" event. When that event fires simply get the new coordinates and zoom level and load markers accordingly.

You can find an example here: https://developers.google.com/maps/documentation/javascript/events

google.maps.event.addListener(map, 'bounds_changed', function() {
    //Get the new location and zoom parameters
    //and print the new markers
});

Upvotes: 4

Related Questions