2011-08-21 23 views
0

中使用對象屬性時,Google地圖不會使用codeigniter和googlemaps v3庫加載我用codeigniter製作了一個網站,並使用googlemaps v3 library將標記添加到地圖。我將數據庫中的位置作爲對象數組獲取,然後我通過foreach每次將位置添加到地圖中循環。如果我輸入一個字符串作爲infowindow_content,那麼一切正常,信息氣泡會在點擊標記時彈出。當我使用位置對象的屬性,雖然地圖沒有加載。當我在infowindow_content

下面是一些示例代碼:

$this->load->library('Googlemaps'); 
    $towers = $this->towers_model->get_towers(); 

    $config['center'] = '18.557394170647473, -9.31640625'; 
    $config['zoom'] = '2'; 
    $this->googlemaps->initialize($config); 

    foreach($towers as $tower) { 
     $marker = array(); 
     $marker['position'] = $tower->Lat.', '.$tower->Long; 
     $marker['infowindow_content'] = '<p>'.$tower->Dedicn.'</p>'; 
     $marker['icon'] = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|9999FF|000000'; 
     $this->googlemaps->add_marker($marker); 
    } 

    $this->data['map'] = $this->googlemaps->create_map(); 

    $this->template->write('scripts', $this->data['map']['js']); 
    $this->template->write_view('content', 'towers/view_all', $this->data); 
    $this->template->render(); 

正如你可以看到我想要輸出$ tower-> Dedicn當我做地圖是不會加載。我已經迴應了它的想法和它的明確定義和包含內容等等。

+0

分開每個語言。從控制器加載JSON數據,然後編寫一個Javascript簡單函數來檢索JSON數據,並即時創建標記。用這些方法你可以很容易地調試你的代碼...... – toopay

回答

0

啊啊我發現了爲什麼!這是因爲有些結果中有語音標記,它們干擾了JavaScript,因此必須使用str_replace替換「with」才能將它們轉義出來!