最近工作中, 需要通过web app 中确定的经纬度,调起高德App.
面向搜索引擎开发,主要的方案为通过App schema协议,调起对应App,
Android:
androidamap://viewMap?sourceApplication=appname&poiname=abc&lat=xx&lon=xx&dev=0
IOS:
iosamap://viewMap?sourceApplication=applicationName&poiname=A&lat=xxx&lon=xxx&dev=1
简单的实现如下
callMap = () => {
const uAgent = navigator.userAgent;
const isAndroid = uAgent.indexOf('Android') > -1 || uAgent.indexOf('Linux') > -1;
const isIos = uAgent.indexOf('iPhone') > -1;
let href;
setTimeout( () => {
if (document.hidden || document.webkitHidden) return ;
href = 'https://uri.amap.com/marker?position=121.287689,31.234527';
this.callLink(href)
},3000);
if (isAndroid) {
href = 'androidamap://viewMap?sourceApplication=appname&poiname=abc&lat=36.2&lon=116.1&dev=0';
this.callLink(href);
}
if (isIos) {
href = 'iosamap://viewMap?sourceApplication=applicationName&poiname=A&lat=39.98848272&lon=116.47560823&dev=1';
this.callLink(href)
}
};
callLink = (href) => {
const a = document.createElement('a');
a.href = href;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};