# add geo
This commit is contained in:
parent
89d570fb57
commit
434d9bd012
|
@ -1,6 +1,7 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<div id="map-container" tabindex="0"></div>
|
||||
<div id="tip"></div>
|
||||
<div v-show="flag" id="panel"></div>
|
||||
<div v-show="mapClick && flag" id='bt-wrapper'>
|
||||
<div id='bt'>点击去高德地图</div>
|
||||
|
@ -159,6 +160,19 @@ export default {
|
|||
closeInfoWindow() {
|
||||
this.map.clearInfoWindow()
|
||||
},
|
||||
onComplete(data) {
|
||||
var str = ['定位成功']
|
||||
str.push('经度:' + data.position.getLng())
|
||||
str.push('纬度:' + data.position.getLat())
|
||||
if (data.accuracy) {
|
||||
str.push('精度:' + data.accuracy + ' 米')
|
||||
}
|
||||
str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'))
|
||||
document.getElementById('tip').innerHTML = str.join('<br>')
|
||||
},
|
||||
onError() {
|
||||
document.getElementById('tip').innerHTML = '定位失败'
|
||||
},
|
||||
getDevicesInitMap(params) {
|
||||
fetchDeviceList(params).then(response => {
|
||||
this.deviceList = response.data.results
|
||||
|
@ -171,11 +185,26 @@ export default {
|
|||
map: map,
|
||||
panel: 'panel'
|
||||
}
|
||||
this.sleep(500)
|
||||
this.sleep(300)
|
||||
const button = document.getElementById('bt')
|
||||
AMap.plugin(['AMap.ToolBar', 'AMap.Scale', 'AMap.Driving'], () => {
|
||||
AMap.plugin(['AMap.ToolBar', 'AMap.Scale', 'AMap.Driving', 'AMap.Geolocation'], () => {
|
||||
map.addControl(new AMap.ToolBar())
|
||||
map.addControl(new AMap.Scale())
|
||||
const geolocation = new AMap.Geolocation({
|
||||
enableHighAccuracy: true,
|
||||
timeout: 10000,
|
||||
buttonOffset: new AMap.Pixel(10, 20),
|
||||
zoomToAccuracy: true,
|
||||
buttonPosition: 'RB'
|
||||
})
|
||||
map.addControl(geolocation)
|
||||
geolocation.getCurrentPosition()
|
||||
// 返回定位信息
|
||||
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 = () => {
|
||||
|
@ -186,7 +215,6 @@ export default {
|
|||
}
|
||||
})
|
||||
})
|
||||
// const driving = new AMap.Driving(drivingOptions)
|
||||
this.flag = true
|
||||
// if (AMap.UA.mobile) {
|
||||
// document.getElementById('panel').style.display = 'none'
|
||||
|
|
Loading…
Reference in New Issue