Проблема в отбрасывании нескольких булавок на карте Google в координаторе

Я хочу добавить несколько пин-кодов в карту Google с динамическим значением, поэтому ниже мой код.

ПОСМОТРЕТЬ

<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);

}

Когда я запускаю код, указанный выше, пропускается только один контакт, но мне нужно несколько контактов с динамическим значением, так как я могу сделать это возможным? все ваши предложения будут заметны.

1

Решение

Замените ваш код этим кодом:

контроллер:

    $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);

Ваш взгляд идеален, не нужно менять.

1

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]