当前位置:   article > 正文

VUE_H5页面跳转第三方地图导航,兼容微信浏览器

VUE_H5页面跳转第三方地图导航,兼容微信浏览器

在这里插入图片描述
当前项目是uniapp项目,若不是需要替换uni.showActionSheet选择api

onMap(address = '', organName = '', longitude = 0, latitude = 0){
	var ua = navigator.userAgent.toLowerCase();
	var isWeixin = ua.indexOf('micromessenger') != -1;
	if(isWeixin) {
		const mapUrl_tx = "http://apis.map.qq.com/uri/v1/marker?marker=coord:" + latitude + "," + longitude + ";title:" + organName + ";addr:" + address + "&referer=yellowpage";
		window.open(mapUrl_tx)
		return false
	}
	const actions = [{id:1, name: '腾讯地图' }, {id:2, name: '百度地图' }, {id:3, name: '高德地图' }]
	uni.showActionSheet({
		itemList: actions.map(item => item.name),
		success: (res)=> {
			let url = "";
			const u = navigator.userAgent;
			const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
			const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') >-1;
			let index = actions[res.tapIndex].id
			if(isAndroid){
				switch (index) {
					case 1:
						url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=H7JBZ-5WUWN-BHDFN-SEHOK-RREKF-I3BD5`;
						break;
					case 2:
						url = `baidumap://map/marker?location=${latitude},${longitude}&title=${address}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
						break;
					case 3:
						url = `androidamap://viewMap?sourceApplication=appname&poiname=${address}&lat=${latitude}&lon=${longitude}&dev=0`;
						break;
					default:
						break;
				}
				if (url != "") {
					window.open(url,"_blank")
				}
			}else if(isiOS){
				switch (index) {
					case 1:
						url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=H7JBZ-5WUWN-BHDFN-SEHOK-RREKF-I3BD5`;
						break;
					case 2:
						url = `baidumap://map/marker?location=${latitude},${longitude}&title=${address}&content=${address}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
						break;
					case 3:
						url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${address}&lat=${latitude}&lon=${longitude}&dev=0`;
						break;
					default:
						break;
				}
				if (url != "") {
					window.open(url,"_blank")
				}
			}
		},
		fail: function (res) {
			console.log(res.errMsg)
		}
	})
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/420936
推荐阅读
相关标签
  

闽ICP备14008679号