-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html~
78 lines (67 loc) · 2.01 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Compass Example</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<link rel="stylesheet" href="css/ol.css" type="text/css">
<link rel="stylesheet" href="css/layout.css" type="text/css">
<script src="js/ol.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
// The watch id references the current `watchHeading`
var watchID = null;
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
startWatch();
var view = new ol.View2D({
center: ol.proj.transform([8.82 , 45], 'EPSG:4326', 'EPSG:3857'),
//rotation: rotation,
zoom: 4
})
var map = new ol.Map({
target: 'map',
layers: [ new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: view
});
}
// Start watching the compass
//
function startWatch() {
// Update compass every 3 seconds
var options = { frequency: 3000 };
watchID = navigator.compass.watchHeading(onSuccess, onError, options);
}
// Stop watching the compass
//
function stopWatch() {
if (watchID) {
navigator.compass.clearWatch(watchID);
watchID = null;
}
}
// onSuccess: Get the current heading
//
function onSuccess(heading) {
var element = document.getElementById('heading');
element.innerHTML = 'Heading: ' + heading;
}
// onError: Failed to get the heading
//
function onError() {
alert('onError!');
}
</script>
</head>
<body>
<div id="heading">Waiting for heading...</div>
<button onclick="startWatch();">Start Watching</button>
<button onclick="stopWatch();">Stop Watching</button>
<div id="map" class="map"></div>
</body>
</html>