Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
91 lines (80 loc) · 2.68 KB
/
Copy pathindex.html
File metadata and controls
91 lines (80 loc) · 2.68 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
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>Geo4map</title>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<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>
</head>
<body>
<div id="map" class="map"></div>
<div id="heading">Waiting for heading...
<button onclick="startWatch();">Start Watching</button>
<button onclick="stopWatch();">Stop Watching</button>
</div>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
<script type="text/javascript" charset="utf-8">
// The watch id references the current `watchHeading`
var watchID = null;
// Wait for device API libraries to load
document.addEventListener("deviceready", initializeMap, false);
// device APIs are available
//
function onDeviceReady() {
startWatch();
}
// Start watching the compass
//
function startWatch() {
// Update compass every 3 seconds
var options = { frequency: 3000 };
view.setRotation(view.getRotation() + Math.PI / 4);
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.magneticHeading;
}
// onError: Failed to get the heading
//
function onError(compassError) {
alert('Compass error: ' + compassError.code);
}
</script>
<script type="text/javascript">
function initializeMap() {
var rotation = heading.magneticHeading;
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
});
}
</script>
</body>
</html>