I have sample code. It is calling latitude and longitude value and marking it on maps.
But i want my all record latitude and longitude show on maps not just one. I know i need change my code for call all value (i must use while
or foreach
) it is ok but i don't know how can i add it on map and i need like MarkerClusterer Cause i have many value on database. I did a search but did not succeed.
Regards
My Code:
<?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>
Query your database with AJAX. Loop through the results to create each marker. There are plenty of examples around. Then you can refer to the MarkerClusterer documentation http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/examples.html to create your marker clusters.
一个简单的解决方案是使用php中的标记集群: http : //www.appelsiini.net/2008/introduction-to-marker-clustering-with-google-maps 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.