-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
69 lines (58 loc) · 1.92 KB
/
map.html
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
67
68
69
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<div id="map" style="width: 800px; height: 680px;"></div>
<script type="text/javascript">
function dateFormat(date) {
var y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
var w = date.getDay();
var wNames = ['日', '月', '火', '水', '木', '金', '土'];
m = ('0' + m).slice(-2);
d = ('0' + d).slice(-2);
return y + '年' + m + '月' + d + '日 (' + wNames[w] + ')';
}
function attachMessage(marker, msg) {
google.maps.event.addListener(marker, 'click', function(event) {
new google.maps.InfoWindow({
content: msg
}).open(marker.getMap(), marker);
});
}
var data = new Array();
$.ajax({
url: "gpshistory.json",
}).success(function(res){
hist=JSON.parse(res)
hist.sort(function(a,b) {
return (a.date < b.date ? 1 : -1);
});
var myMap = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: new google.maps.LatLng(hist[0].latitude,hist[0].longitude),
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
});
hist.forEach(function(s){
console.log(s)
data.push({position: new google.maps.LatLng(s.latitude, s.longitude),
content: "<img src='" +s.src+ "' height=150>" +"<div>" + dateFormat(new Date(s.date)) +"</div>"
});
for (i = 0; i < data.length; i++) {
var myMarker = new google.maps.Marker({
position: data[i].position,
map: myMap,
icon: new google.maps.MarkerImage(
s.icon,
new google.maps.Size(31,31),
new google.maps.Point(0,0),
new google.maps.Point(16,16)
)
});
attachMessage(myMarker, data[i].content);
}
})
}).error(function(data){
alert('error!!!');
});
</script>