How to add Multiple-Markers in google map

前端 未结 1 1083
谎友^
谎友^ 2021-01-28 02:41

I need to add multiple marker in a google map (added google map by using googlemap library).I also added a marker in this map. for a single marker code :

Controller:

1条回答
  •  伪装坚强ぢ
    2021-01-28 03:11

    You can change your code as following solution.

    Changes in your Controller:

    $data['tunnels'] = $this->functional->getTunnelData();
    $config['center'] = '37.4419, -122.1419';
    $config['zoom'] = 'auto';
    $this->googlemaps->initialize($config);
    
    // First Marker
    $marker = array();
    $marker['position'] = '37.429, -122.1519';
    $marker['infowindow_content'] = 'Welcome Googel Map';
    $marker['icon'] = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|9999FF|000000';
    $this->googlemaps->add_marker($marker);
    
    // Second Marker
    $marker = array();
    $marker['position'] = '37.409, -122.1319';
    $marker['draggable'] = TRUE;
    $marker['animation'] = 'DROP';
    $this->googlemaps->add_marker($marker);
    
    // third Marker
    $marker = array();
    $marker['position'] = '37.449, -122.1419';
    $marker['onclick'] = 'alert("You just clicked on Maker!!")';
    $this->googlemaps->add_marker($marker);
    
    // Add Dyanamic Place name In Infowindow content
    if(!empty($data['tunnels'])){
        foreach ($data['tunnels'] as $value) {
            $marker = array();
            $marker['position'] = $value->name.",".$value->city_name.",".$value->state_name.",".$value->country_name;
            $marker['infowindow_content'] = $value->name.",".$value->city_name.",".$value->state_name.",".$value->country_name;
            $marker['icon'] = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|9999FF|000000';
            $this->googlemaps->add_marker($marker);
        }
    }
    
    $data['map'] = $this->googlemaps->create_map();
    

    I hope this will helps you. Thanks!

    0 讨论(0)
提交回复
热议问题