地理位置定位的幾種方式:IP地址,GPS,Wifi,GSM/CDMA地理位置獲取流程:1、用戶打開需要獲取地理位置的web應用。2、應用向瀏覽器請求地理位置,瀏覽器彈出詢問,詢問用戶是否共享地理位置。3、假設用戶允許,瀏覽器從設別查詢相關信息。4、瀏覽器將相關信息發送到一個信任的位置服務器,服務器返回具體的地理位置。
HTML5地理地位的實現: 1. 實現基於瀏覽器(無需后端支持)獲取用戶的地理位置技術 2. 精確定位用戶的地理位置( 精度最高達10m之內,依賴設備 ) 3. 持續追蹤用戶的地理位置 4. 與 Google Map、或者 Baidu Map 交互呈現位置信息。
HTML5中地理位置定位的方法
Geolocation API存在於navigator對象中,只包含3個方法:1、getCurrentPosition //當前位置2、watchPosition //監視位置3、clearWatch //清除監視
getCurrentPosition(success,error,option)方法最多可以有三個參數:第一個參數是成功獲取位置信息的回調函數,它是方法唯一必須的參數;第二個參數用於捕獲獲取位置信息出錯的情況,第三個參數是配置項。
******************************************獲取自己當前的位置
(!DOCTYPE html)
(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)