Commit c961b4ef authored by 彭佳妮(贵阳日报)'s avatar 彭佳妮(贵阳日报)
parents 53bb941d e956c401
......@@ -68,7 +68,7 @@
<view class="shop-map-phone">
<image
mode="aspectFill"
@click="selectMapApp"
@click="openMapApp(shopInfo)"
class="img1"
src="@/static/shop/map.png"
></image>
......@@ -284,9 +284,7 @@ import {
addImgUrlPrefixToImages,
getDistance,
addImgUrlPrefix,
openAmap,
openBaiduMap,
openTencentMap,
navigationSelect,
} from '@/utils/common';
const imgUrl = import.meta.env.VITE_APP_IMG_URL;
const current = ref(0);
......@@ -403,26 +401,31 @@ function getLocationFn() {
/**
* 跳转地图
*/
function selectMapApp() {
xma.showActionSheet({
itemList: ['高德地图', '百度地图', '腾讯地图'],
function openMapApp(info) {
console.log('info', info);
uni.showActionSheet({
itemList: ['高德地图', '百度地图'],
success: (res) => {
const latitude = 39.90960456049752; // 示例纬度
const longitude = 116.3972282409668; // 示例经度
const name = '测试'; // 目标地点名称
const item = {
shopAddress: info.shopAddress,
latitude: info.location.lat,
longitude: info.location.lon,
name: '',
};
console.log('item', item);
switch (res.tapIndex) {
case 0:
// 打开高德地图
openAmap(latitude, longitude, name);
item.name = '高德地图';
navigationSelect(item);
break;
case 1:
item.name = '百度地图';
// 打开百度地图
openBaiduMap(latitude, longitude);
break;
case 2:
// 打开腾讯地图
openTencentMap(latitude, longitude, name);
navigationSelect(item);
break;
default:
break;
......
......@@ -73,30 +73,55 @@ export function debounce(func, wait) {
}, wait);
};
}
/**
* 跳转地图
* @param {*} param0
*/
export function navigationSelect(item) {
console.log(item);
const { osName } = uni.getSystemInfoSync();
const { name, latitude, longitude, shopAddress } = item;
const to = {
name: shopAddress,
longitude,
latitude,
};
const getMapScheme = (to) => {
const u = navigator.userAgent;
const isAndroid = osName === 'android';
export function openMapApp(url, packageName, appName) {
plus.runtime.openURL(url, function (e) {
xma.showModal({
title: '提示',
content: `${appName} 未安装,是否前往应用市场下载?`,
success: function (res) {
if (res.confirm) {
plus.runtime.openURL(`market://details?id=${packageName}`);
}
},
});
});
}
const andriodBaidu = (to) => {
return `bdapp://map/direction?destination=name:${to.name}|latlng:${to.latitude},${to.longitude}&coord_type=gcj02&mode=driving&src=andr.jianghu.jianhao`;
};
export function openAmap(latitude, longitude, name) {
const url = `amapuri://poi?sourceApplication=uniapp&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
openMapApp(url, 'com.autonavi.minimap', '高德地图');
}
export function openBaiduMap(latitude, longitude) {
const url = `baidumap://map/geocoder?location=${latitude},${longitude}`;
openMapApp(url, 'com.baidu.BaiduMap', '百度地图');
}
export function openTencentMap(latitude, longitude, name) {
const url = `qqmap://map/marker?marker=coord:${latitude},${longitude};title:${name}&referer=uniapp`;
openMapApp(url, 'com.tencent.map', '腾讯地图');
const iOSBaidu = (to) => {
return `baidumap://map/direction?destination=name:${to.name}|latlng:${to.latitude},${to.longitude}&coord_type=gcj02&mode=driving&src=ios.jianghu.jianhao`;
};
const andriodGaode = (to) => {
return `amapuri://route/plan/?sourceApplication=mhc&dlat=${to.latitude}&dlon=${to.longitude}&dname=${to.name}&dev=0&t=0`;
};
const iOSGaode = (to) => {
return `iosamap://path?sourceApplication=mhc&dlat=${to.latitude}&dlon=${to.longitude}&dname=${to.name}&dev=0&t=0`;
};
if (item.name === '百度地图') {
if (isAndroid) {
return andriodBaidu(to);
} else {
return iOSBaidu(to);
}
} else if (item.name === '高德地图') {
if (isAndroid) {
return andriodGaode(to);
} else {
return iOSGaode(to);
}
}
};
const a = document.createElement('a');
document.body.appendChild(a);
a.href = getMapScheme(to);
a.click();
href.value = getMapScheme(to);
}
......@@ -41,7 +41,7 @@ export default defineConfig({
// 代理配置
proxy: {
'/api': {
target: 'http://test.rhhzkj.com:8080',
target: 'http://192.168.0.147:9999',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment