uni-App H5网页 导航功能

2021-03-09  本文已影响0人  郭的妻

1.首先你需要申请 腾讯地图 key

2.使用 HBuilder X 编辑器的 小伙伴 们

3.找到uni-app 项目的 manifest.json 文件 如图


image.png

4.打开 manifest.json 文件 选择H5配置 如图


image.png

5.选择H5配置后 找到定位和地图 如图


image.png

6.在你需要使用 导航的页面 以下 添加点击事件

注意:只有在真机上测试有效,在电脑上模拟手机是不行的
/* 点击 导航位置 */
        OpenLocation(lat,lng){
            console.log(lat,lng)
            if(lat && lng){
                uni.getLocation({
                    type: 'gcj02', //返回可以用于uni.openLocation的经纬度
                    success: function (res) {
                        console.log(res);
                        uni.openLocation({
                            latitude: Number(lat),
                            longitude:Number(lng),
                            success: function (res) {
                                console.log(res);
                                console.log('success');
                            }
                        });
                    }
                });
            }else{
                this.showToast('暂无位置信息无法导航位置哦');
            }
        },
上一篇下一篇

猜你喜欢

热点阅读