2013-01-19 62 views
-1

如何根據標記從mysql數據庫檢索值並在infowindow中顯示?如何從mysql數據庫檢索值到google map中的infowindow?

示例第一個標記,信息窗口應顯示「A」..現在,它顯示所有內容。我該怎麼做呢?請引導我。謝謝!

<script> 
     var map; 
     var marker; 
     var infowindow; 

     var info = <?php echo json_encode($infoWindow); ?>; 
     var placeX= <?php echo json_encode($getX); ?>; 
     var placeY= <?php echo json_encode($getY); ?>; 

     function initialize() 
     { 
      var mapProp = { 
       center:new google.maps.LatLng(1.35208,103.81984), 
       zoom:11, 
       mapTypeId:google.maps.MapTypeId.ROADMAP 
       }; 

      map = new google.maps.Map(document.getElementById("googleMap"),mapProp); 

      for(var x=0; x<placeX.length; x++) 
      { 
       retrieve(placeX[x],placeY[x],info[x]) 
      } 

     } 

     function retrieve(x,y,i) 
     { 
      var marker=new google.maps.Marker({ 
       position:new google.maps.LatLng(y,x), 
       }); 

      marker.setMap(map); 

      marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png') 



      marker.info = new google.maps.InfoWindow ({content: '<b>No. of people who choose this location:</b> '+ info}); 
      google.maps.event.addListener(marker, 'click',function(){ 
       marker.info.open(map,marker); 
       }); 

     } 

     function addInfoWindow(x,y,h) 
     { 
      var infowindow = new google.maps.InfoWindow({ 
       content:"Hello World!" 
       }); 

      google.maps.event.addListener(marker, 'click', function() { 
      infowindow.open(map,marker); 
      }); 
     } 

     google.maps.event.addDomListener(window, 'load', initialize); 

    </script> 
+0

這真的很難通過看你提供的信息告訴。你知道如何使用PHP的MySQL數據庫?數據庫中存儲的數據如何? – bfavaretto

回答

0

包含信息的retrieve的說法是i沒有info

marker.info = new google.maps 
.InfoWindow ({content: '<b>No. of people who choose this location:</b> '+ i}); 
//------------------------------------------------------------------------^ 

相關評論:(適用不同的標記的最高值)

把這個權利var info = <?php echo json_encode($infoWindow); ?>;


max=Math.max.apply(null,info); 

將定義一個變量與最高值作爲信息的最大項目。

現在你可以使用這個值有條件標記:

marker.setIcon('http://maps.google.com/mapfiles/ms/icons/'+ 
        ((i==max)?'red':'‌​green')+'-dot.png'); 
+0

謝謝你的幫助!最後,它找到了幾個小時後纔開始工作。謝謝! – screamalltheway

+0

我可以問問是否有方法更改標記的顏色示例:選擇此位置的人數:3(最高數字),​​標記的顏色將變爲紅色。 – screamalltheway

+0

當信息只包含數字,這應該工作:'marker.setIcon('http://maps.google.com/mapfiles/ms/icons/'+((i == 3)?'紅色':'綠色')+' - dot.png');' –