# 定位后显示路径

This commit is contained in:
xianfuxing 2018-09-04 20:19:58 +08:00
parent 2773ea5856
commit 14a2a86635
1 changed files with 17 additions and 16 deletions

View File

@ -172,6 +172,21 @@ export default {
}
str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'))
document.getElementById('geo-tip').innerHTML = str.join('<br>')
const drivingOptions = {
map: this.map,
panel: 'panel'
}
//
const driving = new AMap.Driving(drivingOptions)
const button = document.getElementById('bt')
driving.search(new AMap.LngLat(113.344095, 22.673091), new AMap.LngLat(113.203460828994, 22.64902452257), (status, result) => {
button.onclick = () => {
driving.searchOnAMAP({
origin: result.origin,
destination: result.destination
})
}
})
},
onError() {
document.getElementById('geo-tip').innerHTML = '定位失败'
@ -184,12 +199,8 @@ export default {
this.coordinate = [113.203460828994, 22.64902452257]
}
const map = new AMap.Map('map-container')
const drivingOptions = {
map: map,
panel: 'panel'
}
this.map = map
this.sleep(300)
const button = document.getElementById('bt')
AMap.plugin(['AMap.ToolBar', 'AMap.Scale', 'AMap.Driving', 'AMap.Geolocation'], () => {
map.addControl(new AMap.ToolBar())
map.addControl(new AMap.Scale())
@ -198,6 +209,7 @@ export default {
timeout: 10000,
buttonOffset: new AMap.Pixel(10, 20),
zoomToAccuracy: true,
panToLocation: false,
buttonPosition: 'RB'
})
map.addControl(geolocation)
@ -206,17 +218,6 @@ export default {
AMap.event.addListener(geolocation, 'complete', this.onComplete)
//
AMap.event.addListener(geolocation, 'error', this.onError)
//
const driving = new AMap.Driving(drivingOptions)
driving.search(new AMap.LngLat(113.344095, 22.673091), new AMap.LngLat(113.203460828994, 22.64902452257), (status, result) => {
button.onclick = () => {
driving.searchOnAMAP({
origin: result.origin,
destination: result.destination
})
}
})
})
this.flag = true
// if (AMap.UA.mobile) {