Closed Matrix1990 closed 11 years ago
Hi Matrix,
My only thoughts on this are that you give each 'type' of marker (ie. bars and restaurants) different and unique IDs. In the library, when adding a marker, you can specify it's ID like so:
$marker = array();
$marker['position'] = 'lat, lng';
$marker['id'] = 'MY_ID';
$this->googlemaps->add_marker($marker);
The above would produce a marker with ID 'marker_MY_ID'.
It looks like you already kind of attempted to do this based on the code you provided, however in your code each marker would have the same ID.
The way I have been able to achieve this was as follows:
Step 1 In your view initialise some JavaScript variables, one for each type:
var marker_bar = new Array;
var marker_restaurant = new Array;
Step 2 Set the ID of the markers to use these arrays:
$marker = array();
$marker['id'] = "bar[0]";
$marker['position'] = 'lat, lng';
$this->googlemaps->add_marker($marker);
$marker = array();
$marker['id'] = "bar[1]";
$marker['position'] = 'lat, lng';
$this->googlemaps->add_marker($marker);
$marker = array();
$marker['id'] = "restaurant[0]";
$marker['position'] = 'lat, lng';
$this->googlemaps->add_marker($marker);
$marker = array();
$marker['id'] = "restaurant[1]";
$marker['position'] = 'lat, lng';
$this->googlemaps->add_marker($marker);
Notice how the id is turning the markers into an array? Our marker IDs are now marker_bar[0], marker_bar[1], marker_restaurant[0] and marker_restaurant[1].
Step 3 We can now toggle these with JS. For example, to hide just the bars we can do this:
for (var i in marker_bar)
{
marker_bar[i].setMap(null);
}
I hope that helps.
Sir, I am trying to get a marker by id to put a single marker on the map but I am unable to do the task, will you please help me get this out ? I can show you the code snippet if you want to see it ?
I am using codeigniter and this library file to display the google map settings:
https://github.com/BIOSTALL/CodeIgniter-Google-Maps-V3-API-Library/blob/master/application/libraries/Googlemaps.php
In my header the js is displayed as this: <?php echo $map['js']; ?>
and my data is stored in a database and pulled in using the contollers and models:
model:
function get_coordinates() { $return = array(); $query = $this->db->get('markers');
Controller:
public function index() {
} I am trying to add a toggle feature in the view so if you click the bar button, the bar markers show and so on. I am having difficulty grabbing the marker id and types to even start this due to the js being stored in a variable and when i relocate the js to a file it keeps refreshing so it removes my code.
Does anyone have any idea with this library to add a toggle feature in as i cant even do a click event and alert anything out!
I am attempting something similar to this without the sidebar: http://www.geocodezip.com/v3_MW_example_categories.html
Just unsure of where and how to edit and keep what i write as the js variable keeps changing it!
Thanks!