html5 定位 得到當前位置的經緯度

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError, {
// 指示瀏覽器獲取高精度的位置,默認爲false
enableHighAccuracy: true,
// 指定獲取地理位置的超時時間,默認不限時,單位爲毫秒
timeout: 5000,
// 最長有效期,在重複獲取地理位置時,此參數指定多久再次獲取位置。
maximumAge: 3000
});
} else {
alert("Geolocation is not supported by this browser.此設備不支持定位");
}
    function showPosition(position) {            lat = position.coords.latitude;//緯度            lng = position.coords.longitude;//經度            //alert("lat==>"+lat+"===>"+lng);            //alert((typeof(lat) == undefined);            requestData(cId);        }        function showError(error) {            switch (error.code) {                case error.PERMISSION_DENIED: // 用戶不容許地理定位//                alert("User denied the request for Geolocation.");                    break;                case error.POSITION_UNAVAILABLE: //沒法獲取當前位置                    alert("沒法獲取您當前的位置,請打開GPS後重試.");                    break;                case error.TIMEOUT: //  操做超時//                alert("The request to get user location timed out.");                    break;                case error.UNKNOWN_ERROR://                alert("An unknown error occurred.");                    break;            }        }
相關文章
相關標籤/搜索