設備-地理定位

一、地理定位git

1 navigator.geolocation.getCurrentPosition(function(where){
2    alert(where.coords.latitude + "," + where.coords.longitude);
3 })
1 var geo = navigation.geolocation,
2       lcn_success = function(where){},
3       lcn_error = function(){};
4 geo.getCurrentPosition(lcn_success ,lcn_error );

定位操做時刻發生watchPosition:函數

1  navigator.geolocation.watchPosition(function(where){
2      alert(where.coords.latitude + "," + where.coords.longitude);
3  })

取消查看用戶的定位信息,須要使用具備獨立ID的clearWatch()類函數:spa

1 var geo = navigation.geolocation,
2      watchID = geo.watchPosition(),
3      endWatch = document.getElementById("stop");
4 endWatch.addEventListener('click',function(){
5      geo.clearWatch(watchID);
6 },false)
相關文章
相關標籤/搜索