获取本浏览器经纬度坐标
生活随笔
收集整理的這篇文章主要介紹了
获取本浏览器经纬度坐标
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>
<p id="demo">
點擊這個按鈕,獲得您的坐標:
</p>
<button onclick="getLocation()">
試一下
</button>
<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) {
x.innerHTML = "維度Latitude: " + position.coords.latitude + "<br />經度Longitude: " + position.coords.longitude;
}
function showError(error) {
alert('獲取經緯度錯誤捕獲');
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>
獲取兩個坐標之間的直線距離
// 百度地圖API功能--計算距離
var map = new BMap.Map("allmap");
var pointA = new BMap.Point( Longitude , Latitude ); // 創建點坐標A
var pointB = new BMap.Point( Longitude , Latitude ); // 創建點坐標B
alert('兩點的距離是:'+(map.getDistance(pointA,pointB)).toFixed(2)+' 米。'); //獲取兩點距離,保留小數點后兩位
查詢獲取到的經緯度 http://www.gpsspg.com/maps.htm
百度經緯度查詢:http://api.map.baidu.com/lbsapi/getpoint/index.html
百度官方手冊 http://developer.baidu.com/map/reference/index.php
總結
以上是生活随笔為你收集整理的获取本浏览器经纬度坐标的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CAN总线数据帧/标准帧/扩展帧/远程帧
- 下一篇: 百度云破解版&&第三方下