在微信浏览器直接使用微信导航
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
latitude | number | 是 | 纬度,范围为-90~90,负数表示南纬。使用 gcj02 国测局坐标系 | |
longitude | number | 是 | 经度,范围为-180~180,负数表示西经。使用 gcj02 国测局坐标系 | |
scale | number | 18 | 否 | 缩放比例,范围5~18 |
name | string | 否 | 位置名 | |
address | string | 否 | 地址的详细说明 | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
示例代码
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经纬度
success (res) {
const latitude = res.latitude
const longitude = res.longitude
wx.openLocation({
latitude, // 纬度,浮点数,范围为90 ~ -90
longitude, // 经度,浮点数,范围为180 ~ -180。
name, // 位置名
scale: 18, // 地图缩放级别,整形值,范围从1~28。默认为最大
})
})
}
})
H5移动端打开百度,高德,腾讯地图并判断运营平台 判断运行平台
latitude纬度,longitude经度,name定位地名,
isAndroidOrIOS(latitude, longitude, name, num) {
console.log(latitude, longitude, name, num);
var u = navigator.userAgent;
var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
if (isAndroid) {
console.log("android");
switch (num) {
case 0:
// 腾讯
window.location.href = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
break;
case 1:
// 百度
window.location.href = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
break;
case 2:
// 高德
window.location.href = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
// androidamap://viewMap?sourceApplication=appname&poiname=name&lat=latitude&lon=longitude&dev=0"
break;
default:
break;
}
let hidden = window.document.hidden;
if (typeof hidden == false || !hidden) {
this.$toast("请确认安装该地图,并使用浏览器打开");
}
// return "android";
}
if (isiOS) {
console.log("ios");
switch (num) {
case 0:
window.location.href = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
break;
case 1:
window.location.href = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
break;
case 2:
window.location.href = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
break;
default:
break;
}
let hidden = window.document.hidden;
if (typeof hidden == false || !hidden) {
this.$toast("请确认安装该地图,并使用浏览器打开");
}
// return "ios";
}
// return false;
},