簡體   English   中英

如何使用數據庫中的緯度和經度值在Google地圖上顯示?

[英]how to use latitude and longitude value from my database to show on google map?

我有示例代碼。 它調用緯度和經度值並將其標記在地圖上。

但是我希望我所有記錄的緯度和經度都顯示在地圖上,而不僅僅是一個。 我知道我需要更改代碼以調用所有值(我必須使用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>

用AJAX查詢數據庫。 循環搜索結果以創建每個標記。 周圍有很多例子。 然后,您可以參考MarkerClusterer文檔http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/examples.html來創建標記集群。

一個簡單的解決方案是使用php中的標記集群: http : //www.appelsiini.net/2008/introduction-to-marker-clustering-with-google-maps

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM