|
@@ -0,0 +1,84 @@
|
|
|
|
+export function handleNavigation(toData) {
|
|
|
|
+ console.log("s-xsxd", toData)
|
|
|
|
+ if (!toData.latitude || !toData.longitude || !toData.name) return
|
|
|
|
+ // 微信
|
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
|
+ uni.openLocation({
|
|
|
|
+ ..._obj,
|
|
|
|
+ latitude: parseFloat(toData.latitude),
|
|
|
|
+ longitude: parseFloat(toData.longitude),
|
|
|
|
+ success: function (res) {
|
|
|
|
+ console.log('打开系统位置地图成功')
|
|
|
|
+ },
|
|
|
|
+ fail: function (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ console.log(toData, '---')
|
|
|
|
+ // #endif
|
|
|
|
+ console.log(toData, '---')
|
|
|
|
+ // #ifdef APP-PLUS
|
|
|
|
+ // 判断系统安装的地图应用有哪些, 并生成菜单按钮
|
|
|
|
+ let _mapName = [
|
|
|
|
+ { title: '高德地图', name: 'amap', androidName: 'com.autonavi.minimap', iosName: 'iosamap://' },
|
|
|
|
+ { title: '百度地图', name: 'baidumap', androidName: 'com.baidu.BaiduMap', iosName: 'baidumap://' },
|
|
|
|
+ { title: '腾讯地图', name: 'qqmap', androidName: 'com.tencent.map', iosName: 'qqmap://' },
|
|
|
|
+ ]
|
|
|
|
+
|
|
|
|
+ // 根据真机有的地图软件 生成的 操作菜单
|
|
|
|
+ let buttons = []
|
|
|
|
+ let platform = uni.getSystemInfoSync().platform
|
|
|
|
+ platform === 'android' && _mapName.forEach(item => {
|
|
|
|
+ if (plus.runtime.isApplicationExist({ pname: item.androidName })) {
|
|
|
|
+ buttons.push(item)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ platform === 'ios' && _mapName.forEach(item => {
|
|
|
|
+ console.log(item.iosName)
|
|
|
|
+ if (plus.runtime.isApplicationExist({ action: item.iosName })) {
|
|
|
|
+ buttons.push(item)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ console.log(buttons, '---')
|
|
|
|
+ if (buttons.length) {
|
|
|
|
+ plus.nativeUI.actionSheet({ //选择菜单
|
|
|
|
+ title: "选择地图应用",
|
|
|
|
+ cancel: "取消",
|
|
|
|
+ buttons: buttons
|
|
|
|
+ }, function (e) {
|
|
|
|
+ let _map = buttons[e.index - 1]
|
|
|
|
+ openURL(_map, platform, toData)
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: '请安装地图软件',
|
|
|
|
+ icon: 'none'
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ // #endif
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 打开第三方程序实际应用
|
|
|
|
+function openURL(map, platform, toData) {
|
|
|
|
+ let _defaultUrl = {
|
|
|
|
+ android: {
|
|
|
|
+ "amap": `amapuri://route/plan/?sid=&did=&dlat=${toData.latitude}&dlon=${toData.longitude}&dname=${toData.name}&dev=0&t=0`,
|
|
|
|
+ 'qqmap': `qqmap://map/routeplan?type=drive&to=${toData.name}&tocoord=${toData.latitude},${toData.longitude}&referer=fuxishan_uni_client`,
|
|
|
|
+ 'baidumap': `baidumap://map/direction?origin=${toData.selfLocation.latitude},${toData.selfLocation.longitude}&destination=name:${toData.name}|latlng:${toData.latitude},${toData.longitude}&coord_type=wgs84&mode=driving&src=andr.baidu.openAPIdemo"`
|
|
|
|
+ },
|
|
|
|
+ ios: {
|
|
|
|
+ "amap": `iosamap://path?sourceApplication=fuxishan_uni_client&dlat=${toData.latitude}&dlon=${toData.longitude}&dname=${toData.name}&dev=0&t=0`,
|
|
|
|
+ 'qqmap': `qqmap://map/routeplan?type=drive&to=${toData.name}&tocoord=${toData.latitude},${toData.longitude}&referer=fuxishan_uni_client`,
|
|
|
|
+ 'baidumap': `baidumap://map/direction?origin=${toData.selfLocation.latitude},${toData.selfLocation.longitude}&destination=name:${toData.name}|latlng:${toData.latitude},${toData.longitude}&mode=driving&src=ios.baidu.openAPIdemo`
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ let newurl = encodeURI(_defaultUrl[platform][map.name]);
|
|
|
|
+ console.log(newurl)
|
|
|
|
+ plus.runtime.openURL(newurl, function (res) {
|
|
|
|
+ console.log(res)
|
|
|
|
+ uni.showModal({
|
|
|
|
+ content: res.message
|
|
|
|
+ })
|
|
|
|
+ }, map.androidName ? map.androidName : '');
|
|
|
|
+}
|