2011-11-04 4 views
0

내 Google지도 아이콘 창에 링크를 추가하려고합니다. 하지만 내 코드는 마커와 창만 표시하지만 링크는 표시하지 않습니다. Google Map marker 창

나는이 줄에 링크를 추가하기 위해 노력하고있어 :

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

하는 링크가 내 인덱스 컨트롤러의 일부 기능으로 이동을 클릭 할 때. 하지만 링크가 창에 표시되지 않는 이유는 무엇입니까?

컨트롤러 :

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


} 

모델 :

public function ll($id = '') 
    { 

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

    } 
      } 

내 코드에서 생성 된 HTML (지도 부분 만) :

 <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

우리는 볼 필요가 :

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

이 시도 :

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

이 있어야한다 더 많은 코드 ... 예를 들어 'infowindow_content'로 무엇을합니까? – duncan

+0

'infowindow_content'는 마커 창에 표시 할 문자열 값을 사용합니다. "hi"라고 쓰면 마커 창에 hi가 표시됩니다. 일반 "hi"대신 클릭 할 수있는 링크로 hi를 추가하고 싶습니다. – martan

+0

@martan 정보창에 html 코드를 입력 할 수 있습니다. 아마도 'hi'로 표시됩니다. 또한 젠드 프레임 워크를 사용하고 있습니까? – kjy112

답변

0

문제는이 라인이다 :

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

InfoWindow의 내용은 실제 HTML 코드가 포함 된 문자열입니다. 당신이 생성 된 HTML에서 볼 수 귀하의 경우, <?php 블록은 무시된다 :

<?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>";