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