標籤:style blog http io color ar os 使用 java
1、 載入百度API的核心js,ak表示擷取百度地圖的開發密鑰,免費的需要申請下
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=42b8ececa9cd6fe72ae4cddd77c0da5d"></script>
2、代碼:
//設定預設地理位置 訪問失敗時使用預設地理位置
var defaultPosition="121.48479060028a31.234309729773";
1 if($.cookie("appPoi")==null||$.cookie("appPoi")=="undefined"||$.cookie("appPoi")==undefined){ 2 var geolocation = new BMap.Geolocation(); 3 geolocation.getCurrentPosition(function(r){ 4 if (r.point != undefined) { 5 $lng = r.point.lng; 6 $lat = r.point.lat; 7 } 8 if (r.longitude != undefined) { 9 $lng = r.longitude;10 $lat = r.latitude;11 }12 if($lng != 0){ 13 $.cookie("appPoi",$lng + "a" + $lat,{expires:1});14 }15 if(this.getStatus() == BMAP_STATUS_SUCCESS){16 appPoi = $lng + "a" + $lat;17 } else {18 appPoi = defaultPosition;19 }20 21 },{ enableHighAccuracy: true,22 timeout:3000,23 maximumAge:5000*60});24 }else{25 appPoi = $.cookie("appPoi");26 }
在後台 接受到經緯度後裔‘a‘為分隔字元分開並進行位址解析(解析方法見工具類)
js 擷取地理位置經緯度