我正在尝试定位用户并使用传单将地图设置到此位置:
I'm trying to locate a user and set the map to this position with leaflet:
<script>
var map;
function initMap(){
map = new L.Map('map',{zoomControl : false});
var osmUrl = 'http://{s}.tile.openstreetmap.org/mapnik_tiles/{z}/{x}/{y}.png',
osmAttribution = 'Map data © 2012 OpenStreetMap contributors',
osm = new L.TileLayer(osmUrl, {maxZoom: 18, attribution: osmAttribution});
map.setView(new L.LatLng(51.930156,7.189230), 7).addLayer(osm);
}
function locateUser(){
map.locate({setView : true});
}
</script>
在执行浏览器请求许可,但没有任何反应?我的代码有什么问题?
On execute the browser ask for permission, but then nothing happens? What's wrong with my code?
您的地图变量范围存在问题.我在这里发布了一个修复您的代码的示例:http://jsfiddle.net/XwbsU/3/
You have an issue with the scope of your map variable. I have posted an example that fixes your code here: http://jsfiddle.net/XwbsU/3/
当您点击找到我!"时,您应该会收到浏览器地理位置弹出窗口.
You should receive the browser geolocation popup when you click 'Find me!'.
希望对你有所帮助.
这篇关于如何使用传单定位定位用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!