1.获取当前的地理位置
type:'wgs84'返回gps坐标,无法获取到address
'gcj02'返回国测局坐标,可以获取到address
uni.getLocation({
geocode: true,
type: 'gcj02',
success: (res) => {
this.latitude = res.latitude;
this.longitude = res.longitude;
//地址信息(仅App端支持,需配置geocode为true)
this.current_address = res.address.province + res.address.city + res.address .district + res.address.street + res.address.streetNum + res.address.poiName;
this.navigaToShop();
}
})
2.判断是否安装高德app,安装并唤起app进行导航
navigaToShop(item) {
let shop_latitude = item.latitude;//目的地纬度
let shop_longtude = item.longitude;//目的地经度
let shop_address =item.stationname;//目的地地址
let current_latitude = this.latitude;//当前纬度
let current_longitude = this.longitude;//当前经度
var packageName = 'com.autonavi.minimap';
var main = plus.android.runtimeMainActivity();
var packageManager = main.getPackageManager();
var PackageManager = plus.android.importClass(packageManager);
var packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
if (packageInfo)
{
var Uri = plus.android.importClass("android.net.Uri");
var url = "amapuri://route/plan?sourceApplication=maxuslife" + "&sid=A&slat=" + current_latitude + "&slon=" + current_longitude + "&sname=" + this .current_address + "&did=B&dlat=" + shop_latitude + "&dlon=" + shop_longtude + "&dname=" + shop_address + "D10&dev=0&t=0";
var Intent = plus.android.importClass('android.content.Intent');
var intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
var uri = Uri.parse(url);
//将功能Scheme以URI的方式传入
data intent.setData(uri);
intent.setPackage("com.autonavi.minimap");
var main = plus.android.runtimeMainActivity();
main.startActivity(intent);
} else {
uni.showToast({ icon: 'none', title: `未安装高德导航APP,请先安装` })
} },