|
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 |