[英]Get user's exact location
我正在創建一個網站,在該網站中我需要獲取最接近用戶位置的記錄。 我不想從用戶那里獲得他所在位置的輸入。 如何獲取確切的用戶位置,以使記錄更接近他的位置?
您要檢索什么數據? 該坐標? 地址?
您可以使用普通的javascript獲取坐標:
// check to see if the browser supports geolocation
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(showCoordData);
}
function showCoordData(data){
// in data.coords you'll have latitude, longitude, accuracy,
// altitudeAccuracy, heading, and speed
console.log(data.coords);
}
如果您想從坐標中獲取街道地址,城市,州等,那么使用Google Maps或Bing Maps API可能會更好。 (顯然,我會首先嘗試使用Google)。
https://developers.google.com/maps/documentation/javascript/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.