2011-04-27 22:11:24 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Leaflet mobile example</title>
|
2012-02-14 23:02:29 +08:00
|
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
|
|
|
2011-04-27 22:11:24 +08:00
|
|
|
<link rel="stylesheet" href="../dist/leaflet.css" />
|
2012-02-14 23:02:29 +08:00
|
|
|
|
2011-04-27 22:11:24 +08:00
|
|
|
<script src="../dist/leaflet.js"></script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
html, body, #map {
|
|
|
|
height: 100%;
|
|
|
|
}
|
2012-02-14 23:02:29 +08:00
|
|
|
</style>
|
2011-04-27 22:11:24 +08:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="map"></div>
|
|
|
|
|
|
|
|
<script>
|
2012-07-25 23:51:38 +08:00
|
|
|
var map = L.map('map');
|
2012-02-14 23:02:29 +08:00
|
|
|
|
2014-04-28 19:16:15 +08:00
|
|
|
L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
|
2012-07-25 23:51:38 +08:00
|
|
|
maxZoom: 18,
|
2014-04-28 19:16:15 +08:00
|
|
|
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
|
|
|
|
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
|
|
|
|
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
|
2014-05-15 04:58:41 +08:00
|
|
|
id: 'examples.map-i86knfo3'
|
2012-07-25 23:51:38 +08:00
|
|
|
}).addTo(map);
|
2012-02-14 23:02:29 +08:00
|
|
|
|
2011-04-28 05:11:52 +08:00
|
|
|
function onLocationFound(e) {
|
2011-05-19 22:29:37 +08:00
|
|
|
var radius = e.accuracy / 2;
|
|
|
|
|
2012-07-25 23:51:38 +08:00
|
|
|
L.marker(e.latlng).addTo(map)
|
|
|
|
.bindPopup("You are within " + radius + " meters from this point").openPopup();
|
2012-02-14 23:02:29 +08:00
|
|
|
|
2012-07-25 23:51:38 +08:00
|
|
|
L.circle(e.latlng, radius).addTo(map);
|
2011-04-28 05:11:52 +08:00
|
|
|
}
|
2012-02-14 23:02:29 +08:00
|
|
|
|
2011-04-28 05:11:52 +08:00
|
|
|
function onLocationError(e) {
|
2011-05-19 22:29:37 +08:00
|
|
|
alert(e.message);
|
2011-04-28 05:11:52 +08:00
|
|
|
}
|
2012-07-25 23:51:38 +08:00
|
|
|
|
|
|
|
map.on('locationfound', onLocationFound);
|
|
|
|
map.on('locationerror', onLocationError);
|
|
|
|
|
|
|
|
map.locate({setView: true, maxZoom: 16});
|
2011-04-27 22:11:24 +08:00
|
|
|
</script>
|
|
|
|
</body>
|
2012-02-14 23:02:29 +08:00
|
|
|
</html>
|