Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Api marker in layers

I'm doing a project with Google Maps Api v3. I am wanting to carry a full list of points that will have restaurants, and wanted to somehow allow the user to select the type of restaurant, showing and hiding as the type.

This is possible with layers, or is it more correct, I clear all points and upload them on the map again, this can make it slow.

tks

like image 355
Tiedt Tech Avatar asked Aug 30 '13 20:08

Tiedt Tech


1 Answers

You don't need to remove them and add them again to your map. One approach you can do is create separate arrays for the different "types" of restaurants from your original array. And create a set of markers based on the each of the different arrays.

There is a marker option called visible that you can set when you instantiate your markers, you can set this to false to start. Then based on what layer is selected (say on a checkbox), you can toggle the visibility using the setVisible(true/false) method on each of the markers in your selected array.

Here is a demo of how you can implement this (only have it for one array, but the same would follow for all your arrays of restaurant types) - this would essentially mimic turning on/off layers on a map.

like image 111
Suvi Vignarajah Avatar answered Sep 19 '22 09:09

Suvi Vignarajah