0
A
回答
1
用途看我的定位API,它將有助於每秒獲取當前位置。您只需存儲一個位置(服務器)並從另一個位置的經度中獲取。
var id, target, options;
function success(pos) {
var crd = pos.coords;
if (target.latitude === crd.latitude && target.longitude === crd.longitude) {
console.log('Congratulations, you reached the target');
navigator.geolocation.clearWatch(id);
}
};
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
};
target = {
latitude : 0,
longitude: 0,
}
options = {
enableHighAccuracy: false,
timeout: 5000,
maximumAge: 0
};
id = navigator.geolocation.watchPosition(success, error, options);
1
您可以使用HTML5
The HTML Geolocation API is used to get the geographical position of a user. Since this can compromise user privacy, the position is not available unless the user approves it.
試試下面的代碼支持地理位置API:
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your position.</p>
<button onclick="getLocation()">Try It</button>
<div id="mapholder"></div>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var latlon = position.coords.latitude + "," + position.coords.longitude;
var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="
+latlon+"&zoom=14&size=400x300&sensor=false";
document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
</script>
</body>
</html>
相關問題
- 1. 查找手機的位置
- 2. 查找MAC地址
- 3. 在Android手機中查找地址
- 4. 如何查找Mac機器的DNS服務器IP地址?
- 5. 在java中使用IP地址查找mac地址
- 6. 使用Qt Mobility查找IP地址(在s60手機上)
- 7. 如何使用python查找特定的mac地址
- 8. 如何從PHP中的IP地址查找用戶位置
- 9. 如何使用地理位置查找位置?
- 10. Java - 通過MAC地址找到主機
- 11. 查找使用座標地址或位置
- 12. 使用設備IP地址查找位置
- 13. 登記手冊MAC地址
- 14. 如何讓機器的mac地址
- 15. 如何在不使用API的情況下查找IP地址的位置?
- 16. 在ColdFusion中查找MAC地址
- 17. 如何找到一個mac地址?
- 18. 使用HTML/JavaScript查找地理位置
- 19. 如何在python中設置「ip地址」,「DNS」,「主機名」,「MAC地址」?
- 20. 如何使用findstr獲取MAC地址?
- 21. 如何使用Java 5獲取主機mac地址?
- 22. 如何使用C程序獲取機器的MAC地址?
- 23. 離子角應用中手機的MAC地址
- 24. 虛擬機關機時如何找出Hyper-V虛擬機的MAC地址?
- 25. 如何使用Zipcode查找位置?
- 26. 查找來電位置,同時使用安卓手機通話時使用
- 27. 如何使用C#獲取IP地址的物理(MAC)地址?
- 28. 如何從arp -a掃描中查找MAC地址
- 29. 如何在IRIX上以編程方式查找MAC地址?
- 30. 在手機上,有沒有讓每部手機都不同的「mac地址」?
到目前爲止您嘗試過的是什麼? – 2014-08-28 06:02:38