本文介紹了如何使用傳單定位定位用戶?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試定位用戶并使用傳單將地圖設置到此位置:
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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!