php - Issue in drop multiple pins in google map in coordinator -
i want drop multiple pin in google map dynamic value below 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 clicked me!!")'; $this->googlemaps->add_marker($marker); $data['map'] = $this->googlemaps->create_map(); $this->load->view('test',$data); }
when run above code single pin drop want multiple pins dynamic value how can make possible ? suggestion appreciable .
replace code code:
controller:
$address[ ]=your multiple address //store multiple address in array foreach($address $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 perfect no need change.
Comments
Post a Comment