【问题标题】:How to add Multiple-Markers in google map如何在谷歌地图中添加多个标记
【发布时间】:2018-02-16 00:33:01
【问题描述】:

我需要在谷歌地图中添加多个标记(通过使用 googlemap 库添加谷歌地图)。我还在这张地图中添加了一个标记。 对于单个标记代码:

控制器:

    $data['tunnels'] = $this->functional->getTunnelData();
    $config['center'] = '37.4419, -122.1419';
    $config['zoom'] = 'auto';
    $this->googlemaps->initialize($config);
    $marker = array();
    $marker['position'] = 'center';
    $this->googlemaps->add_marker($marker);
    $data['map'] = $this->googlemaps->create_map();

型号:

    $this->db->select('ult_tunnel.*,ult_country.name as country_name,ult_state.name as state_name,ult_city.name as city_name ')
                    ->join('ult_country','ult_country.id = ult_tunnel.country_id')
                    ->join('ult_state','ult_state.id = ult_tunnel.state_id')
                    ->join('ult_city','ult_city.id = ult_tunnel.city_id')
                    ->from('ult_tunnel')
                    ->where('ult_tunnel.status','Active')
                    ->get()->result();

查看:

    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" id="map">
        <?php echo $map['js']; ?>
        <?php echo $map['html']; ?>
    </div>

请帮我在这个 googlemap 中添加多个标记。 任何帮助将不胜感激。

提前致谢。

已编辑:

表结构: 它包含:

Id(int 主键)

名称(varchar)

国家(整数)

状态(整数)

城市(整数)

状态

我想通过谷歌地图中的名字来标记

【问题讨论】:

    标签: javascript php codeigniter google-maps google-maps-api-3


    【解决方案1】:

    您可以按照以下解决方案更改您的代码。

    控制器的变化:

    $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();
    

    我希望这会对你有所帮助。谢谢!

    【讨论】:

    • 谢谢,很好,但我想动态添加标记。对于前。 (我只是想通过标记显示地名,存储在数据库中)
    • 请发布您的表格结构以获取带经纬度的地点名称。
    猜你喜欢
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 2021-07-22
    • 1970-01-01
    • 2019-05-05
    • 2020-06-08
    • 1970-01-01
    相关资源
    最近更新 更多