2011-11-04 94 views
0

我正在尝试在我的Google地图标记窗口中添加一个链接。但我的代码只显示标记和窗口,但它不显示链接。谷歌地图标记窗口

我想加入这一行的链接:

$marker['infowindow_content'] = "<?php echo anchor('index/get_by_id/$id',{$row->subject} on {$row->address}')?>"; 

当链接被点击它进入我的索引控制器的一些功能。 但为什么链接没有出现在窗口中。 (仅在地图部分)

public function ll($id = '') 
    { 

    $sql = $this->db->get('info'); 
    if ($sql->num_rows() >0) { 
     return $sql; 
    } 
    else{ 
     return null; 

    } 
      } 

从我的代码生成的HTML::

控制器:

    function index() 
{ 


    if(empty($_POST)){ 
    $this->load->helper('form'); 
    $this->googlemaps->initialize(); 
    $marker = array(); 
    //$this->main_model->get_map(); 

    if($result = $this->main_model->ll()){ 
     //var_dump($result); 
     foreach($result->result() as $row) { 
      //var_dump($row); 
      //$data[]=$row; 
      $marker['position'] = "{$row->lat},{$row->lng}"; 
      $id=$row->id; 
      $marker['infowindow_content'] = "<?php echo anchor('index/get_by_id/$id',{$row->subject} on {$row->address}')?>"; 

      $marker['animation'] = 'DROP'; 
      //var_dump($marker['position ']); 
      $this->googlemaps->add_marker($marker); 
     } 
    } 


    //$this->googlemaps->add_marker($marker); 
    $data['map'] = $this->googlemaps->create_map(); 
    $data['list'] = $this->main_model->getdata(); 
    $this->load->view('main_view',$data); 
} 


} 

模型

 <script type="text/javascript"> 
     //<![CDATA[ 

     var map; // Global declaration of the map 
     var iw = new google.maps.InfoWindow(); // Global declaration of the infowindow 
     var lat_longs = new Array(); 
     var markers = new Array(); 
     function initialize() { 

      var myLatlng = new google.maps.LatLng(65.84815, 24.14670); 
      var myOptions = { 
       zoom: 15, 
       center: myLatlng, 
       mapTypeId: google.maps.MapTypeId.ROADMAP} 
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

     var myLatlng = new google.maps.LatLng(65.85051,24.14529); 

     var markerOptions = { 
      position: myLatlng, 
      map: map, 
      animation: google.maps.Animation.DROP  
     }; 
     marker_0 = createMarker(markerOptions); 

     marker_0.set("content", "<?php echo anchor('index/get_by_id/1',street problem on something home)?>"); 

     google.maps.event.addListener(marker_0, "click", function() { 
      iw.setContent(this.get("content")); 
      iw.open(map, this); 

     }); 

     var myLatlng = new google.maps.LatLng(65.84931,24.14555); 

     var markerOptions = { 
      position: myLatlng, 
      map: map, 
      animation: google.maps.Animation.DROP  
     }; 
     marker_1 = createMarker(markerOptions); 

     marker_1.set("content", "<?php echo anchor('index/get_by_id/2',hello on 11 some)?>"); 

     google.maps.event.addListener(marker_1, "click", function() { 
      iw.setContent(this.get("content")); 
      iw.open(map, this); 

     }); 

     var myLatlng = new google.maps.LatLng(65.84858,24.14160); 

     var markerOptions = { 
      position: myLatlng, 
      map: map, 
      animation: google.maps.Animation.DROP  
     }; 
     marker_2 = createMarker(markerOptions); 

     marker_2.set("content", "<?php echo anchor('index/get_by_id/3',problem street on 78900 street)?>"); 

     google.maps.event.addListener(marker_2, "click", function() { 
      iw.setContent(this.get("content")); 
      iw.open(map, this); 

     }); 

     var myLatlng = new google.maps.LatLng(65.85000,24.14773); 

     var markerOptions = { 
      position: myLatlng, 
      map: map, 
      animation: google.maps.Animation.DROP  
     }; 
     marker_3 = createMarker(markerOptions); 

     marker_3.set("content", "<?php echo anchor('index/get_by_id/4',gulshan street on 11 gulshan)?>"); 

     google.maps.event.addListener(marker_3, "click", function() { 
      iw.setContent(this.get("content")); 
      iw.open(map, this); 

     }); 

     var myLatlng = new google.maps.LatLng(65.84620,24.14593); 

     var markerOptions = { 
      position: myLatlng, 
      map: map, 
      animation: google.maps.Animation.DROP  
     }; 
     marker_4 = createMarker(markerOptions); 

     marker_4.set("content", "<?php echo anchor('index/get_by_id/5',broken road on banani)?>"); 

     google.maps.event.addListener(marker_4, "click", function() { 
      iw.setContent(this.get("content")); 
      iw.open(map, this); 

     }); 

     var myLatlng = new google.maps.LatLng(65.84961,24.15164); 

     var markerOptions = { 
      position: myLatlng, 
      map: map, 
      animation: google.maps.Animation.DROP  
     }; 
     marker_5 = createMarker(markerOptions); 

     marker_5.set("content", "<?php echo anchor('index/get_by_id/6',no lamp on arbritary)?>"); 

     google.maps.event.addListener(marker_5, "click", function() { 
      iw.setContent(this.get("content")); 
      iw.open(map, this); 

     }); 


     } 


    function createMarker(markerOptions) { 
     var marker = new google.maps.Marker(markerOptions); 
     markers.push(marker); 
     lat_longs.push(marker.getPosition()); 
     return marker; 
    } 

     window.onload = initialize; 

     //]]> 
+0

我们需要看到更多的代码...你如何处理'infowindow_content'? – duncan

+0

'infowindow_content'将输入想要在标记窗口中显示的字符串值。如果您在其中写入“hi”,标记窗口会显示您好。而不是简单的“嗨”我想添加您好作为一个可点击的链接。 – martan

+0

@martan您可以将HTML代码提供给信息窗口。也许与'hi'。你也使用zend框架? – kjy112

回答

0

的问题是与该线:

$marker['infowindow_content'] = "<?php echo anchor('index/get_by_id/$id',{$row->subject} on {$row->address}')?>"; 

InfoWindow的内容是一个包含实际HTML代码的字符串。在你的情况下,<?php块被忽略,因为你可以在生成的HTML看到:

marker_0.set("content", "<?php echo anchor('index/get_by_id/1',street problem on something home)?>"); 

它必须是:

marker_0.set("content", "<a href='index/get_by_id/1'>street problem on something home</a>"); 

试试这个:

<?php 
    $subject = $row->subject; 
    $address = $row_>address; 
?> 

var index = '<?php echo $id; ?>'; 
var subject = '<?php echo $subject; ?>'; 
var address = '<?php echo $address; ?>'; 

$marker['infowindow_content'] = "<a href='index/get_by_id/" + index + "'>" + subject + " on " + address + "</a>";