gpt4 book ai didi

javascript - 如何在谷歌地图中添加多个标记

转载 作者:行者123 更新时间:2023-12-03 03:31:17 25 4
gpt4 key购买 nike

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

Controller :

    $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>

请帮助我在此谷歌地图中添加多个标记。任何帮助将不胜感激。

提前致谢。

已编辑:

表结构:它包含:

Id(int主键)

名称(varchar)

国家/地区(整数)

状态(整数)

城市(整数)

状态

我想在谷歌地图中通过名称进行标记

最佳答案

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

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

希望这对您有帮助。谢谢!

关于javascript - 如何在谷歌地图中添加多个标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46093485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com