main.js 封装
/*封装 打开高德
json.startW 开始纬度;json.startJ 开始经度
json.endW 目的地纬度;json.endJ 目的地经度
*/
Vue.prototype.Gaode = function (json) {
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="+json.startW+"&slon="+json.startJ+"&sname=当前位置"+
"&did=B&dlat="+json.endW+"&dlon="+json.endJ+"&dname=文化体育活动中心&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
{
alert('未安装' + packageName + '')
}
}
使用
<template>
<view>
<text class="btn2" @click="gaode()">点击导航</text>
</view>
</template>
methods: {
gaode () {
var that = this
uni.showToast({
title: '正在打开高德地图...',
duration: 15000,
icon: 'none'
})
that.Gaode({
'startJ': that.jing,
'startW': that.wei,
'endJ': 115.49341,
'endW': 38.257711
})
}
}