集成BIOSTALL CI Google地图库

时间:2015-05-22 09:49:19

标签: codeigniter google-maps-api-3

我正处于一个项目的中间,并由Steve Marks整合了BIOSTALL CI库并且工作正常。然而,客户的设计扭曲让我在同一个拉链下收集多个项目并在标记中显示列表。我有一系列的项目,我正在尝试做这样的事情

$marker['infowindow_content']=$this->load->view('map_marker',$data,true);

但这不起作用我的地图在此声明后没有加载。我不知道为什么。虽然我直接邮寄给史蒂夫马克斯,他恰好是一个非常好的人帮我解决了另一个问题。然而这次他似乎很忙。我想知道是否有人曾经这样做过。

我当前的地图看起来像like this

我的标记生成代码

$zip_codes=$this->search_model->get_zip_codes();

    for($i=0;$i<count($zip_codes);$i++)
    {
        $data['marker_items']=$this->search_model->get_items_by_zip_code($zip_codes[$i]['zip']);
        $marker = array();
        $marker['position'] = $data['marker_items'][0]['latitude'].','.$data['marker_items'][0]['longitude'];
        $marker['infowindow_content']=$this->load->view('map_marker',$data,true);
        $marker['icon'] = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld='.count($data['marker_items']).'|9999FF|000000';
        $this->googlemaps->add_marker($marker);
    }
    $data['map'] = $this->googlemaps->create_map();

我想知道是否有人可以提供帮助

2 个答案:

答案 0 :(得分:0)

上传googlemaps图书馆

$this->load->library('googlemaps');
// set config
$config['zoom'] = 'auto';
$this->googlemaps->initialize($config);

并加载到视图中使用下面的代码,无需将其分配到数组

 $data['map'] = $this->googlemaps->create_map();
 $this->load->view('map_marker',$data);// not need to pass it in array

查看文件:

<html>
<head><?php echo $map['js']; ?></head>
<body><?php echo $map['html']; ?></body>
</html>

另请阅读CI google api

答案 1 :(得分:0)

public function index(){
    $this->load->library('googlemaps');
    $config['center'] = 'auto';
    $config['zoom'] = 'auto';
    $config['kmlLayerURL'] = 'localhost/khair/google_map/detail';
    $this->googlemaps->initialize($config);
    $marker = array();
    $marker['position'] = '28.6457559,  76.8105583';
    $marker['infowindow_content'] = 'Hi';
    $marker['icon'] = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|9999FF|000000';
    $this->googlemaps->add_marker($marker);

    $marker = array();
    $marker['position'] = '28.6998822, 77.2549408';
    $marker['draggable'] = TRUE;
    $marker['animation'] = 'DROP';
    $this->googlemaps->add_marker($marker);

    $marker = array();
    $marker['position'] = '28.5486782, 77.4549395';
    $marker['onclick'] = 'alert("You just clicked me!!")';
    $this->googlemaps->add_marker($marker);

    /*You can use foreach() to repeat $marker array and values with conditions. */

    $data['map'] = $this->googlemaps->create_map();
    $this->load->view('google_map',$data);

}