uni-app獲取當前位置


uniapp獲取當前城市:

官方api:uni.getLocation()
獲取當前的地理位置、速度。 在微信小程序中,當用戶離開應用后,此接口無法調用,除非申請后台持續定位權限;當用戶點擊“顯示在聊天頂部”時,此接口可繼續調用。

例:

uni.getLocation({
    type: 'wgs84',
    success: function (res) {
        console.log('當前位置的經度:' + res.longitude);
        console.log('當前位置的緯度:' + res.latitude);
    }
});

 

成功回調函數中會返回當前經緯度等信息

如果想獲取當前省市區信息,可以設置參數  geocode  為 true,該屬性僅APP端支持

例:

uni.getLocation({
    type: 'wgs84',
   geocode:true, success: function (res) { console.log(
res.address); } });

 

 APP端還可使用 plus.geolocation 獲取中文地址

plus.geolocation.getCurrentPosition( function(position){
   console.log( position.addresses);
}, function ( e ) {
   console.log( e.message );
},{geocode:true});

其他端可使用地圖開放平台獲取SDK:

https://ask.dcloud.net.cn/article/35070

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM