Marko Cakic
Marko Cakic

Reputation: 7106

Getting marker data from a google map v3

I have a google map v3 with a number of markers, which have a "category" attribute. I also have a left side menu bar, from which a user can select the desired category. When he/she clicks on the selected category, all the markers are cleared from the map, and only markers with the selected category are loaded.

Now, I need some sort of function which can search through the map and get the loaded markers and their data. The data will then be dynamically loaded in the right side menu bar. You can see the page I am talking about at this LINK

Please, any help will be highly appreciated...

Upvotes: 0

Views: 1800

Answers (2)

Mano Marks
Mano Marks

Reputation: 8819

One solution: 1) Create an array of markers. Every time you create a marker, add it to the array. Also assign a property to the marker of 'category' or something.

marker.category='foo';

2) When user clicks on the button, look through your markers array and test if each marker matches the category. If it does not, set the map to null.

if (markers[iterator].category!='foo'){
  markers[iterator].setMap(null);
} else {markers[iterator].setMap(map);}

Upvotes: 1

Sean Mickey
Sean Mickey

Reputation: 7716

I know this isn't the answer you are hoping for, but there is no good way to query the map and ask for all of the markers. As you load the map and create the markers, you want to keep an array of all of your markers or keep an array by category and track your markers in multiple arrays. Keeping an array for each marker type will make it much easier to turn them on/off; that's what I do. Hope this helps -

Upvotes: 1

Related Questions