forked from krvarma/TinyGPS_SparkCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spark_location.html
91 lines (77 loc) · 2.3 KB
/
spark_location.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<title>Spark Core Location</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body
{
height: 100%;
margin: 0px;
padding: 0px;
}
h1
{
text-align: center;
margin-left: auto;
margin-right: auto;
}
#map-canvas
{
width: 80%;
height: 80%;
margin-left: auto;
margin-right: auto;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var map;
var marker;
var loc;
function initialize() {
var mapOptions = {
zoom: 18,
minZoom: 10,
maxZoom: 18,
draggable: false,
disableDefaultUI: true,
center: new google.maps.LatLng(0.0, 0.0)
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
marker = new google.maps.Marker({position: new google.maps.LatLng(0.0, 0.0), map: map});
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
function start() {
var deviceID = "<<devideid>>";
var accessToken = "<<accesstoken>>";
var eventSource = new EventSource("https://api.spark.io/v1/devices/" + deviceID + "/events/?access_token=" + accessToken);
eventSource.addEventListener('open', function(e) {
console.log("Opened!"); },false);
eventSource.addEventListener('error', function(e) {
console.log("Errored!"); },false);
eventSource.addEventListener('gpsloc', function(e) {
var parsedData = JSON.parse(e.data);
var data = parsedData.data.split(",");
console.log( parsedData.data);
console.log(data[0]);
console.log(data[1]);
loc = new google.maps.LatLng(data[0], data[1]);
marker.setMap(null);
marker = new google.maps.Marker({position: loc, map: map});
marker.setMap(null);
map.panTo(loc);
marker.setMap(map);
}, false);
}
window.onload=start;
</script>
</head>
<body>
<h1>Spark Location</h1>
<div id="map-canvas">
</div>
</body>
</html>