JS 调起高德App

最近工作中, 需要通过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);
    };
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容