y***@163.com
y***@163.com
  • 发布:2020-01-07 13:58
  • 更新:2020-05-12 22:25
  • 阅读:3391

uni-app原生打包启动 高德APP规划点到点路线

分类:uni-app

android原生插件,创建module

public class AmapWXModule extends WXSDKEngine.DestroyableModule {  

    @JSMethod(uiThread = true)  
    public void startNaviGao(JSONObject options) {  
        if (mWXSDKInstance.getContext() instanceof Activity) {  
            StringBuffer stringBuffer = new StringBuffer("amapuri://route/plan/");  
            String sid = options.getString("sid");  
            String slat = options.getString("slat");  
            String slon = options.getString("slon");  
            String sname = options.getString("sname");  
            String did = options.getString("did");  
            String dlat = options.getString("dlat");  
            String dlon = options.getString("dlon");  
            String dname = options.getString("dname");  
            String dev = options.getString("dev");  
            String t = options.getString("t");  
            stringBuffer.append("?sid=").append(sid)  
                    .append("&slat=").append(slat)  
                    .append("&slon=").append(slon)  
                    .append("&sname=").append(sname)  
                    .append("&did=").append(did)  
                    .append("&dlat=").append(dlat)  
                    .append("&dlon=").append(dlon)  
                    .append("&dname=").append(dname)  
                    .append("&dev=").append(dev)  
                    .append("&t=").append(t);  
            Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse(stringBuffer.toString()));  
            intent.setPackage("com.autonavi.minimap");  
            mWXSDKInstance.getContext().startActivity(intent);  
        }  
    }  
    @Override  
    public void destroy() {  

    }  
}

dcloud_uniplugins.json添加插件

{  
          "type": "module",  
          "name": "Amap",  
          "class": "com.demo.AmapWXModule"  
        }

uniapp使用

const modal = uni.requireNativePlugin('modal');  
const amap = uni.requireNativePlugin('Amap');  
methods: {  
    AppAmap()  
    {  
        amap.startNaviGao({sid:'A',slat:'36.7025585',slon:'116.8766784700',sname:'开始'  
        ,did:'B',dlat:'36.6494152900',dlon:'117.1224975600',dname:'结束',dev:'1',t:'0'});  
    },  
}

android原生项目app下的build.gradle中添加新增的 module
// 添加uni-app插件
implementation project(':amaplib')

0 关注 分享

要回复文章请先登录注册

1***@qq.com

1***@qq.com

回复 y***@163.com :
大佬,调用高德导航的插件怎么用,救救小白吧
2020-05-12 22:25
y***@163.com

y***@163.com (作者)

调取浏览器
```
var locationX='36.702558';
var locationY='116.876678';
var storeName='demo';
var url = "http://uri.amap.com/navigation?to=" + locationY + "," + locationX + "," +
storeName + "&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0";
var Uri = plus.android.importClass("android.net.Uri");
var uri = Uri.parse(url);
var Intent = plus.android.importClass('android.content.Intent');
var intent = new Intent(Intent.ACTION_VIEW, uri);

var main = plus.android.runtimeMainActivity();
main.startActivity(intent);
```
2020-01-09 16:12
y***@163.com

y***@163.com (作者)

本打算这样使用,但是只能打开高德,不能规划线路
```
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="androidamap://route/plan"+
"?sid='A'&slat='36.702558'&slon='116.876678'&sname='开始'"+
"&did='B'&dlat='36.649415'&dlon='117.122497'&dname='结束'&dev='0'&t='1'";
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 + '')
}
```
有成功的麻烦帮忙指正,这样哪里有问题?
2020-01-07 14:01