001.
<!DOCTYPE html>
002.
<html>
003.
<head>
004.
<link rel=
"icon"
href=
"image/favicon.ico"
type=
"image/x-icon"
/>
005.
<meta name=
"viewport"
content=
"initial-scale=1.0, user-scalable=no"
>
006.
<meta charset=
"utf-8"
>
007.
<title>Device Marker Clustering</title>
008.
<style>
009.
010.
011.
#map {
012.
height: 100%;
013.
}
014.
015.
html, body {
016.
height: 100%;
017.
margin: 0;
018.
padding: 0;
019.
}
020.
</style>
021.
</head>
022.
<body>
023.
<table align=
"center"
><tr><td>
024.
<?php
include
'header.php'
;?>
025.
</td></tr></table>
026.
<div id=
"map"
></div>
027.
<script>
028.
function
initMap() {
029.
var
map =
new
google.maps.Map(document.getElementById(
'map'
), {
030.
center:
new
google.maps.LatLng(18.299615,99.698478),
031.
zoom: 10
032.
});
033.
var
infoWindow =
new
google.maps.InfoWindow;
034.
035.
036.
downloadUrl(
'location.php'
,
function
(data) {
037.
var
xml = data.responseXML;
038.
var
markers = xml.documentElement.getElementsByTagName(
'marker'
);
039.
Array.prototype.forEach.call(markers,
function
(markerElem) {
040.
var
name = markerElem.getAttribute(
'name'
);
041.
var
address = markerElem.getAttribute(
'link'
);
042.
var
image = markerElem.getAttribute(
'image'
);
043.
var
point =
new
google.maps.LatLng(
044.
parseFloat(markerElem.getAttribute(
'lat'
)),
045.
parseFloat(markerElem.getAttribute(
'lng'
)));
046.
047.
048.
var
infowincontent = document.createElement(
'div'
);
049.
050.
var
strong = document.createElement(
'strong'
);
051.
strong.textContent = name
052.
infowincontent.appendChild(strong);
053.
infowincontent.appendChild(document.createElement(
'br'
));
054.
var
text = document.createElement(
'text'
);
055.
056.
text.textContent = address
057.
infowincontent.appendChild(text);
058.
059.
var
marker =
new
google.maps.Marker({
060.
map: map,
061.
content: address,
062.
position: point
063.
});
064.
065.
marker.addListener(
'click'
,
function
() {
066.
infoWindow.setContent(infowincontent);
067.
infoWindow.open(map, marker);
068.
map.setZoom(14);
069.
map.setCenter(marker.getPosition());
070.
});
071.
});
072.
});
073.
}
074.
075.
function
bindInfoWindow(marker, map, infoWindow, html) {
076.
google.maps.event.addListener(marker,
'click'
,
function
() {
077.
infoWindow.setContent(html);
078.
infoWindow.open(map, marker);
079.
});
080.
}
081.
082.
function
downloadUrl(url, callback) {
083.
var
request = window.ActiveXObject ?
084.
new
ActiveXObject(
'Microsoft.XMLHTTP'
) :
085.
new
XMLHttpRequest;
086.
087.
request.onreadystatechange =
function
() {
088.
if
(request.readyState == 4) {
089.
request.onreadystatechange = doNothing;
090.
callback(request, request.status);
091.
}
092.
};
093.
094.
request.open(
'GET'
, url, true);
095.
request.send(null);
096.
}
097.
098.
function
doNothing() {}
099.
100.
</script>
102.
</script>
103.
<script async defer
105.
</script>
106.
</body>
107.
</html>