# 定位后显示路径
This commit is contained in:
parent
2773ea5856
commit
14a2a86635
|
@ -172,6 +172,21 @@ export default {
|
||||||
}
|
}
|
||||||
str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'))
|
str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'))
|
||||||
document.getElementById('geo-tip').innerHTML = str.join('<br>')
|
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() {
|
onError() {
|
||||||
document.getElementById('geo-tip').innerHTML = '定位失败'
|
document.getElementById('geo-tip').innerHTML = '定位失败'
|
||||||
|
@ -184,12 +199,8 @@ export default {
|
||||||
this.coordinate = [113.203460828994, 22.64902452257]
|
this.coordinate = [113.203460828994, 22.64902452257]
|
||||||
}
|
}
|
||||||
const map = new AMap.Map('map-container')
|
const map = new AMap.Map('map-container')
|
||||||
const drivingOptions = {
|
this.map = map
|
||||||
map: map,
|
|
||||||
panel: 'panel'
|
|
||||||
}
|
|
||||||
this.sleep(300)
|
this.sleep(300)
|
||||||
const button = document.getElementById('bt')
|
|
||||||
AMap.plugin(['AMap.ToolBar', 'AMap.Scale', 'AMap.Driving', 'AMap.Geolocation'], () => {
|
AMap.plugin(['AMap.ToolBar', 'AMap.Scale', 'AMap.Driving', 'AMap.Geolocation'], () => {
|
||||||
map.addControl(new AMap.ToolBar())
|
map.addControl(new AMap.ToolBar())
|
||||||
map.addControl(new AMap.Scale())
|
map.addControl(new AMap.Scale())
|
||||||
|
@ -198,6 +209,7 @@ export default {
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
buttonOffset: new AMap.Pixel(10, 20),
|
buttonOffset: new AMap.Pixel(10, 20),
|
||||||
zoomToAccuracy: true,
|
zoomToAccuracy: true,
|
||||||
|
panToLocation: false,
|
||||||
buttonPosition: 'RB'
|
buttonPosition: 'RB'
|
||||||
})
|
})
|
||||||
map.addControl(geolocation)
|
map.addControl(geolocation)
|
||||||
|
@ -206,17 +218,6 @@ export default {
|
||||||
AMap.event.addListener(geolocation, 'complete', this.onComplete)
|
AMap.event.addListener(geolocation, 'complete', this.onComplete)
|
||||||
// 返回定位出错信息
|
// 返回定位出错信息
|
||||||
AMap.event.addListener(geolocation, 'error', this.onError)
|
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
|
this.flag = true
|
||||||
// if (AMap.UA.mobile) {
|
// if (AMap.UA.mobile) {
|
||||||
|
|
Loading…
Reference in New Issue