Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Google Maps API V3 Toggle Markers
#1

[eluser]balboa_1990[/eluser]
I am using codeigniter and this library file to display the google map settings:

https://github.com/BIOSTALL/CodeIgniter-...lemaps.php

In my header the js is displayed as this:
Code:
<?php echo $map['js']; ?>
and my data is stored in a database and pulled in using the contollers and models:

model:

Code:
function get_coordinates() {
        $return = array();

        $query = $this->db->get('markers');

        if ($query->num_rows()>0) {
            foreach ($query->result() as $row) {
            array_push($return, $row);
            }
        }
    return $return;
    }
Controller:

Code:
public function index() {  

        $this->load->library('googlemaps');
        $this->load->model('home_model', '', TRUE);


        $this->googlemaps->initialize();

        $coords = $this->home_model->get_coordinates();


        foreach ($coords as $coordinate) {
            if($coordinate->type == "restaurant"){
                $image = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000';
            }

            if($coordinate->type == "bar"){
                $image = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=B|FFFFFF|000000';
            }

            $marker = array('id'=> $coordinate->type, 'position' => $coordinate->lat.','.$coordinate->lng, 'icon' => $image, 'infowindow_content' =>$coordinate->address);


            $this->googlemaps->add_marker($marker);

        }

        $data = array();

        $data['map'] = $this->googlemaps->create_map();

        $data['page_title'] = "Home";
        $data['content'] = "home";  
        $this->load->view('template', $data);
  }

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!




Theme © iAndrew 2016 - Forum software by © MyBB