作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要在谷歌地图中添加多个标记(通过使用谷歌地图库添加谷歌地图)。我还在这张 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/
我是一名优秀的程序员,十分优秀!