Call the Amap APP on the mobile terminal and display the navigation route

At the beginning, he also found his tune in GaodeAPIAPP method 

The result is to jump to a new page. On that page, click to jump to Amap APP

So I chose to use Android iOS to meet this requirement

1. Logic

First use navigator.userAgent to get the phone model

Then determine whether the device is Android or iOS 

Then call the corresponding method to jump

It's just that he only accepts the starting and ending points

2. Code

let lon = this.DHposition.longitude
let lat = this.DHposition.latitude
let dname = this.DHposition.name
let id = this.DHposition.id
const u = navigator.userAgent
let url
// 判断设备是iOS还是Android,Linux
const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1
// myposition 为我当前位置 [114.361866, 30.540072]
if (isiOS) {
    url = `iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=${this.myposition[1]}&slon=${this.myposition[0]}&sname=当前位置&did=${id}&dlat=${lat}&dlon=${lon}&dname=${dname}&dev=0&t=0`
}
if (isAndroid) {
    url = `amapuri://route/plan/?sid=BGVIS1&slat=${this.myposition[1]}&slon=${this.myposition[0]}&sname=当前位置&did=${id}&dlat=${lat}&dlon=${lon}&dname=${dname}&dev=0&t=0`
}
window.location.href = url

Guess you like

Origin blog.csdn.net/notagoodwriter/article/details/133860126