地理位置定位的幾種方式:IP地址,GPS,Wifi,GSM/CDMA地理位置獲取流程:一、用戶打開須要獲取地理位置的web應用。二、應用向瀏覽器請求地理位置,瀏覽器彈出詢問,詢問用戶是否共享地理位置。三、假設用戶容許,瀏覽器從設別查詢相關信息。四、瀏覽器將相關信息發送到一個信任的位置服務器,服務器返回具體的地理位置。javascript
HTML5地理地位的實現: 1. 實現基於瀏覽器(無需後端支持)獲取用戶的地理位置技術 2. 精肯定位用戶的地理位置( 精度最高達10m以內,依賴設備 ) 3. 持續追蹤用戶的地理位置 4. 與 Google Map、或者 Baidu Map 交互呈現位置信息。 html
HTML5中地理位置定位的方法java
Geolocation API存在於navigator對象中,只包含3個方法:一、getCurrentPosition //當前位置二、watchPosition //監視位置三、clearWatch //清除監視git
getCurrentPosition(success,error,option)方法最多能夠有三個參數:第一個參數是成功獲取位置信息的回調函數,它是方法惟一必須的參數;第二個參數用於捕獲獲取位置信息出錯的狀況,第三個參數是配置項。web
******************************************獲取本身當前的位置後端
(!DOCTYPE html)api
(html xmlns="http://www.w3.org/1999/xhtml")瀏覽器
(head)服務器
(meta http-equiv="Content-Type" content="text/html; charset=utf-8"/)函數
(title)H5地理位置Demo(/title)
(script src="http://api.map.baidu.com/api?v=1.3" type="text/javascript")
(/script)
(/head)
(body)
(div id="aaa" style="border:#ccc solid 1px" width:"697px" height:"500px")(/div)
(script type="text/javascript")
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function (p) {
var latitude = p.coords.latitude//緯度
var longitude = p.coords.longitude;
createmap(latitude, longitude);
}, function (e) {//錯誤信息
var aa = e.code + "\n" + e.message;
alert(aa);
}
);
}
function createmap(a,b)
{
var map = new BMap.Map("aaa");
var point = new BMap.Point(b, a);
map.centerAndZoom(point, 20);//設置地圖的中心點和座標
Window.map = map;//將map變量存儲在全局
}
(/script)
(/body)
(/html)