พอดีตอนนี้ผมกำลังทำในส่วนของ google map อยู่หน่ะครับแล้วติดปัญหาตรงในส่วนของ marker clusterer จึงอยากให้ช่วยทีครับติดมาหลายวันแล้วครับ ขอบคุณล่วงหน้าครับ
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="image/favicon.ico" type="image/x-icon" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Device Marker Clustering</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<table align="center"><tr><td>
<?php include 'header.php';?>
</td></tr></table>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(18.299615,99.698478),
zoom: 10
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP or XML file
downloadUrl('location.php', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) {
var name = markerElem.getAttribute('name');
var address = markerElem.getAttribute('link');
var image = markerElem.getAttribute('image');
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('lat')),
parseFloat(markerElem.getAttribute('lng')));
var infowincontent = document.createElement('div');
//แสดง Name
var strong = document.createElement('strong');
strong.textContent = name
infowincontent.appendChild(strong);
infowincontent.appendChild(document.createElement('br'));
var text = document.createElement('text');
//แสดง Link
text.textContent = address
infowincontent.appendChild(text);
var marker = new google.maps.Marker({
map: map,
content: address,
position: point
});
marker.addListener('click', function() {
infoWindow.setContent(infowincontent);
infoWindow.open(map, marker);
map.setZoom(14);
map.setCenter(marker.getPosition());
});
});
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js">
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDei0Xq1ecoQ0keWl_LWoS4gVHGFFjp2rw&callback=initMap">
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="image/favicon.ico" type="image/x-icon" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Marker Clustering</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 75%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="js/markerclusterer.js"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDei0Xq1ecoQ0keWl_LWoS4gVHGFFjp2rw&callback=initialize"></script>
</head>
<body>
<table width="100%"><tr><td align="center"><?php include 'header.php';?></td></tr></table>
<div id="map"></div>
<script>
function initialize() {
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(18.299615,99.698478),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
// Change this depending on the name of your PHP or XML file
downloadUrl('location.php', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) {
var name = markerElem.getAttribute('name');
var address = markerElem.getAttribute('link');
var image = markerElem.getAttribute('image');
var point = new google.maps.LatLng(parseFloat(markerElem.getAttribute('lat')),parseFloat(markerElem.getAttribute('lng')));
var marker = new google.maps.Marker({
map: map,
position: point,
title : name });
});
var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'images/m'});
});
}
</script>
</body>
</html>