在协调器的 google 地图中删除多个图钉的问题
Issue in drop multiple pins in google map in coordinator
我想在具有动态值的 google 地图中放置多个图钉,下面是我的代码。
VIEW
<html>
<head><?php echo $map['js']; ?></head>
<body><?php echo $map['html']; ?></body>
控制器
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);
}
当我 运行 上面的代码只有一个引脚掉落时,但我想要多个具有动态值的引脚,所以我怎样才能让它成为可能?您的所有建议都会很有价值。
用以下代码替换您的代码:
控制器:
$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);
您的观点很完美,无需更改。
我想在具有动态值的 google 地图中放置多个图钉,下面是我的代码。
VIEW
<html>
<head><?php echo $map['js']; ?></head>
<body><?php echo $map['html']; ?></body>
控制器
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);
}
当我 运行 上面的代码只有一个引脚掉落时,但我想要多个具有动态值的引脚,所以我怎样才能让它成为可能?您的所有建议都会很有价值。
用以下代码替换您的代码:
控制器:
$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);
您的观点很完美,无需更改。