繁体   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