dongqia3502 2015-06-01 08:48 采纳率: 100%
浏览 18
已采纳

在协调员的谷歌地图中删除多个引脚的问题

i want to drop multiple pin in google map with dynamic value so below is my code .

VIEW

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

Controller

function index(){

 $address ="Gondal Road, Dr. Yagnik Road Corner, Near Malaviya Petrol Pump,      Rajkot, Gujarat 360001";// Google HQ
 $prepAddr = str_replace(' ','+',$address);
 $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
 $output= json_decode($geocode);
 $lat = $output->results[0]->geometry->location->lat;
 $long = $output->results[0]->geometry->location->lng;

 $this->load->library('googlemaps');

 $config['center'] = '37.4419, -122.1419';
 $config['zoom'] = 'auto';
 $this->googlemaps->initialize($config);

 $marker = array();
 $marker['position'] = $lat.','.$long;
 $marker['infowindow_content'] = $address;
 $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'] = '37.409, -122.1319';
$marker['draggable'] = TRUE;
$marker['animation'] = 'DROP';
$this->googlemaps->add_marker($marker);

$marker = array();
$marker['position'] = '37.449, -122.1419';
$marker['onclick'] = 'alert("You just clicked me!!")';
$this->googlemaps->add_marker($marker);
$data['map'] = $this->googlemaps->create_map();



 $this->load->view('test',$data);

}

When i run above code only single pin is drop but i want multiple pins with dynamic value so how can i make it possible ? your all suggestion will be appreciable .

  • 写回答

1条回答 默认 最新

  • duanpin2034 2015-06-01 09:20
    关注

    Replace Your Code With this code:

    Controller:

        $address[ ]=Your multiple address  //store your multiple address in array
        foreach($address as $add)
        {
    
            $prepAddr = str_replace(' ','+',$add);
            $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
            $output= json_decode($geocode);
            $lat = $output->results[0]->geometry->location->lat;
            $long = $output->results[0]->geometry->location->lng;
    
            $marker = array();
            $marker['position'] = $lat.','.$long;
            $marker['infowindow_content'] = '$add';
            $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();
        $this->load->view('test',$data);
    

    Your view is perfect no need to change.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?