Built with blockbuilder.org
Last active
October 11, 2017 00:18
-
-
Save 1Cr18Ni9/0f45f38c0ae7fb1bad0c9634e3811651 to your computer and use it in GitHub Desktop.
leafletjs location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta content="yes" name="apple-mobile-web-app-capable" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"> | |
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
#map{ width:100%; height:100%; } | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script> | |
var map = L.map("map"); | |
L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png").addTo(map); | |
function foundLocation(e){ | |
L.marker(e.latlng).addTo(map).bindPopup("Catch You!"); | |
} | |
function notFundLocation(e){ | |
var point = [32.0975, 120.5958333]; | |
map.setView(point, 10); | |
L.marker(point).addTo(map).bindPopup("Some where"); | |
alert("Unable to find your location. You may need to enable Geolocation."); | |
} | |
map.on("locationfound", foundLocation); | |
map.on("locationerror", notFundLocation); | |
map.locate({ setView:true, maxZoom:10 }); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment