-
Notifications
You must be signed in to change notification settings - Fork 2
/
geolocation.html
44 lines (39 loc) · 1.28 KB
/
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
<!DOCTYPE html>
<html>
<head>
<title>MapQuest Leaflet plugin with HTML5 geolocation</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
<script src="//www.mapquestapi.com/sdk/leaflet/v2.s/mq-map.js?key=KEY"></script>
<script type="text/javascript">
"use strict";
var L, MQ, map;
window.onload = function() {
if (navigator.geolocation) {
// the html5 geolocation function will ask you if you agree to be located
navigator.geolocation.getCurrentPosition(function (position) {
map = L.map('map', {
layers: MQ.mapLayer(),
center: [position.coords.latitude, position.coords.longitude],
zoom: 18
});
}, function (err) {
document.getElementById('map').innerHTML = err.message;
});
} else {
document.getElementById('map').innerHTML = "Geolocation is not supported by this browser.";
}
};
</script>
<style>
#map {
width: 800px;
height: 600px;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</html>