您好,欢迎来到尚佳旅游分享网。
搜索
您的当前位置:首页uniapp获取当前定位

uniapp获取当前定位

来源:尚佳旅游分享网
uniapp获取当前定位

需要打开⼿机的gps开关,正常的授权也要有判断当前设备是否打开gps开关

checkOpenGPSServiceByAndroid () {

let system = uni.getSystemInfoSync();// 获取系统信息 if (system.platform === 'android') { // 判断平台

var context = plus.android.importClass(\"android.content.Context\");

var locationManager = plus.android.importClass(\"android.location.LocationManager\"); var main = plus.android.runtimeMainActivity();

var mainSvr = main.getSystemService(context.LOCATION_SERVICE); if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) { uni.showModal({ title: '提⽰',

content: '请打开定位服务功能',

showCancel: false, // 不显⽰取消按钮 success() {

if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) { var Intent = plus.android.importClass('android.content.Intent');

var Settings = plus.android.importClass('android.provider.Settings');

var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); main.startActivity(intent); // 打开系统设置GPS服务页⾯ } } }); } } },

获取当前定位,经纬度转地址

getnow() {

uni.getLocation({ type: 'wgs84', geocode: true, success: (res) =>{

let point = new plus.maps.Point(res.longitude, res.latitude); plus.maps.Map.reverseGeocode( point, {}, (event) =>{

let address = event.address; // 转换后的地理位置 let point = event.coord; // 转换后的坐标信息

let coordType = event.coordType; // 转换后的坐标系类型 let reg = /.+?(省|市|⾃治区|⾃治州|县|区)/g;

let addressList = address.match(reg).toString().split(\ console.log(addressList,'位置信息') } ) } });},

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- shangjiatang.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务