js 擷取地理位置經緯度

來源:互聯網
上載者:User

標籤: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 擷取地理位置經緯度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.