-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
66 lines (62 loc) · 1.69 KB
/
index.html
File metadata and controls
66 lines (62 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
<head>
<style>
#map {
height: 100%;
width: 100%;
left: 0;
position: absolute;
top: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var trap = "http://i.imgur.com/HzPa48c.png";
function initMap() {
var mapDiv = document.getElementById('map');
var map = new google.maps.Map(mapDiv, {
center: {lat: 43.6532, lng: -79.3832},
zoom: 8
});
update(function(data){
var newData = JSON.parse(data)['data'];
for (var index in newData) {
var axis = new google.maps.LatLng(newData[index]['latitude'], newData[index]['longitude']);
var id = newData[index]['_id'];
addMarker(axis, id, map);
}
});
}
function update(callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "queryLocation");
var data;
xhr.onload = function() {
data = xhr.response;
callback(data);
}
xhr.send();
}
function addMarker(axis, title, map){
var contentString = "<h3>ID : " + title + "</h3>"
var marker = new google.maps.Marker({
position: axis,
title: title,
icon: trap
});
var infowindow = new google.maps.InfoWindow({
content: contentString
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
marker.setMap(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
async defer></script>
</body>
</html>