我有示例代码。它调用纬度和经度值并将其标记在地图上。
但我希望所有记录的纬度和经度都显示在地图上,而不仅仅是一个。我知道我需要更改代码以调用所有值(我必须使用while
或foreach
),这是可以的,但是我不知道如何在地图上添加它,并且需要像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 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 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来创建标记集群。
关于javascript - 如何使用数据库中的纬度和经度值在Google map 上显示?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21099856/