前端回调
// 获取当前位置
getPosition: function() {
_self.GetLocation(function(res) {
if (res) {
_self.longitude = res.longitude;// 经度
_self.latitude = res.latitude;//纬度
_self.address = res.address;//五级地址
}
})
},
方法封装
GetLocation:function(callBack) {
//#ifdef APP-PLUS
let system = uni.getSystemInfoSync() //获取系统信息
if (system.platform == "android" || 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);
var gpsProvider = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER); //检查是否开启了GPS
if (!gpsProvider) {
uni.showModal({
tit