-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.geolocation.html
143 lines (125 loc) · 3.88 KB
/
5.geolocation.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html>
<head>
<!-- http://sangu.be/test/5.geolocation.html -->
<meta charset="utf-8" />
<style type="text/css">
body {
margin: 0;
background-color: #404040;
}
#map {
position: absolute;
top: 50px;
left: 250px;
width: 800px;
height: 600px;
}
#output {
border: 1px solid black;
position: absolute;
width: 200px;
height: 300px;
color: white;
}
</style>
<script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
var _map;
$(function () {
// Create a Bing map
_map = new Microsoft.Maps.Map(document.getElementById("map"),
{ credentials: "Ak3Sjc32qVKfI0CiNObHGFEuq_fIeN4kq2zzjNDEqbu9Gmjpbj7bN3wkmCZvas8C" });
// Get the current position from the browser
if (!navigator.geolocation) // or: Modernizr.geolocation
alert("This browser doesn't support geolocation");
else
navigator.geolocation.getCurrentPosition(onPositionReady, onError);
// Third property: "PositionOptions" object
// enableHighAccuracy (bool) - iPhone, Android, ...
// timeout (long in ms)
// maximumAge (long in ms)
// var watchId = watchPosition(...)
// -> Same parameters
// -> Works like setInterval/clearInterval
// -> Will be called whenever the user's location changes
// -> clearWatch(watchId) when done
});
function onPositionReady(position) {
// Apply the position to the map
var location = new Microsoft.Maps.Location(position.coords.latitude, position.coords.longitude);
_map.setView({ zoom: 18, center: location });
// Add a pushpin to the map representing the current location
var pin = new Microsoft.Maps.Pushpin(location);
_map.entities.push(pin);
// Check available data
document.getElementById("Latitude").innerHTML = position.coords.latitude;
document.getElementById("Longitude").innerHTML = position.coords.longitude;
document.getElementById("Altitude").innerHTML = position.coords.altitude;
document.getElementById("Accuracy").innerHTML = position.coords.accuracy;
document.getElementById("AltitudeAccuracy").innerHTML = position.coords.altitudeAccuracy;
document.getElementById("Heading").innerHTML = position.coords.heading;
document.getElementById("Speed").innerHTML = position.coords.speed;
}
function onError(err) {
switch (err.code) {
// err.message: DOMString - not intended for end users
case 0:
alert("Unknown error");
break;
case 1:
alert("The user said no!");
break;
case 2:
alert("Location data unavailable");
break;
case 3:
alert("Location request timed out");
break;
}
}
</script>
</head>
<body>
<div id="map"></div>
<div>
<table id="output">
<tr>
<td>Latitude *</td>
<td id="Latitude"></td>
</tr>
<tr>
<td>Longitude * </td>
<td id="Longitude"></td>
</tr>
<tr>
<td>Altitude</td>
<td id="Altitude"></td>
</tr>
<tr>
<td>Accuracy *</td>
<td id="Accuracy"></td>
</tr>
<tr>
<td>Altitude Accuracy</td>
<td id="AltitudeAccuracy"></td>
</tr>
<tr>
<td>Heading</td>
<td id="Heading"></td>
</tr>
<tr>
<td>Speed</td>
<td id="Speed"></td>
</tr>
<tr>
<td colspan=2>
<a href="6.history.html">history API</a>
</td>
</tr>
</table>
</div>
</body>
</html>