H5 定位

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
</body>

</html>



js代碼

//獲取當前定位

navigator.geolocation.getCurrentPosition(function(result){
console.log(result);
},function(error){
console.log(error)
});

//監視定位

var watchID = navigator.geolocation.watchPosition(function (result) {
    console.log(result);
},function (error) {
    console.log(error);
});


//說明

navigator.geolocation地理位置 API 允許用戶向 Web 應用程序提供他們的位置。出於隱私考慮,報告地理位置前會先請求用戶許可 

getCurrentPosition有兩種方法 getCurrentPosition() 和 watchPosition()

getCurrentPosition()獲取當前定位

 

watchPosition()監視定位




發佈了41 篇原創文章 · 獲贊 25 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章