<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
</body>
<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()監視
定位