查看: 20|回复: 0

uni-app获取当前位置

[复制链接]

0

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2008-10-22
发表于 2019-10-10 13:57:00 | 显示全部楼层 |阅读模式

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

 



来源:https://www.cnblogs.com/angenstern/p/11647549.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部