2014-01-13 35 views
0

我有示例代碼。它調用經緯度值並在地圖上標記。如何使用我的數據庫中的緯度和經度值在谷歌地圖上顯示?

但我想在地圖上的不只是一個我所有的記錄經緯度顯示。我知道我需要改變我的代碼,呼叫所有值(我必須使用whileforeach)是確定,但我不知道我怎樣才能將其添加在地圖上,我需要一個像MarkerClusterer因爲我對數據庫中的許多價值。 我做了一個搜索,但沒有成功。

問候

我的代碼:

<?php 
include_once("db.php"); 
$db=new database; 

$query= mysql_query("SELECT * FROM firsatlar"); 

$array=mysql_fetch_array($sorgu); 

$place=explode(":", $array["latLngs"],2); 

$lat= $place[0]; //latitude 
$lng= $place[1]; //longitude 

?> 
<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
    <meta charset="utf-8"> 
    <title>Info windows</title> 
    <style> 
     html, body, #map-canvas { 
     height: 100%; 
     margin: 0px; 
     padding: 0px 
     } 
    </style> 
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
    <script> 


function initialize() { 
    var myLatlng = new google.maps.LatLng(<?php echo $lat?>,<?php echo $lng?>); 
    var mapOptions = { 
    zoom: 4, 
    center: myLatlng 
    }; 

    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); 

    var contentString = '<div id="content">'+ 
     '<div id="siteNotice">'+ 
     '</div>'+ 
     '<h1 id="firstHeading" class="firstHeading"></h1>'+ 
     '<div id="bodyContent">'+ 
     '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' + 
     'sandstone rock formation in the southern part of the '+ 
     'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+ 
     'south west of the nearest large town, Alice Springs; 450&#160;km '+ 
     '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+ 
     'features of the Uluru - Kata Tjuta National Park. Uluru is '+ 
     'sacred to the Pitjantjatjara and Yankunytjatjara, the '+ 
     'Aboriginal people of the area. It has many springs, waterholes, '+ 
     'rock caves and ancient paintings. Uluru is listed as a World '+ 
     'Heritage Site.</p>'+ 
     '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+ 
     'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+ 
     '(last visited June 22, 2009).</p>'+ 
     '</div>'+ 
     '</div>'; 

    var infowindow = new google.maps.InfoWindow({ 
     content: contentString 
    }); 

    var marker = new google.maps.Marker({ 
     position: myLatlng, 
     map: map, 
     title: 'Uluru (Ayers Rock)' 
    }); 
    google.maps.event.addListener(marker, 'click', function() { 
    infowindow.open(map,marker); 
    }); 
} 

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

    </script> 
    </head> 
    <body> 
    <div id="map-canvas"></div> 
    </body> 
</html> 

回答

1

查詢與AJAX數據庫。循環瀏覽結果以創建每個標記。有很多例子。然後,你可以參考MarkerClusterer文檔​​創建您的標記集羣。

+0

感謝您回答@MrUpsidown。我看到了這些文檔,但是我的知識還不足以做到這一點。我不知道如何用我的代碼做到這一點。你可以看到人們給予否定的觀點,我的問題對他們來說可能太簡單了。再次感謝您花時間 –

+0

那麼你需要一步一步來這裏。就拿一個AJAX請求的PHP頁面的一個簡單的例子,嘗試去了解它是如何工作的,等你不明白downvotes因爲你的問題太簡單了,而是因爲它已經被回答,或者因爲你沒有把足夠的努力說清楚。 – MrUpsidown

相關問題