生活随笔
收集整理的這篇文章主要介紹了
vue使用高德地图web端JSAPI 路线规划、搜索提示教程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
高德地圖web端JSAPI
效果圖
搜索提示
路線規劃
引入依賴
npm i @amap
/amap
-jsapi
-loader
--save
vue代碼
注意:key:申請web端JSAPI的key
securityJsCode是申請key對應的秘鑰
申請地址:https://console.amap.com/dev/key/app
<template
><div
>起始位置:
<el
-input id
="start" v
-model
="startName"></el
-input
>結束位置:
<el
-input id
="end" v
-model
="endName"></el
-input
><el
-button @click
="goView">查詢
</el
-button
><div id
="container" /></div
>
</template
><script
>
import AMapLoader
from '@amap/amap-jsapi-loader'export default {name: 'AMapView',data() {return {map: null,startName: '',endName: ''}},mounted() {window
._AMapSecurityConfig
= {securityJsCode: '' }this.initMap()},methods: {goView() {const driving
= new AMap.Driving({map: this.map
,policy: AMap
.DrivingPolicy
.LEAST_TIME})const points
= [{ keyword: this.startName
, city: '全國' },{ keyword: this.endName
, city: '全國' }]driving
.search(points
, (status, result) => {console
.log('status=', status
)console
.log('result=', result
)})},initMap() {AMapLoader
.load({key: '', version: '2.0', plugins: ['AMap.ToolBar', 'AMap.Driving', 'AMap.AutoComplete'] }).then(AMap => {this.map
= new AMap.Map('container', { viewMode: '3D', zoom: 5, center: [105.602725, 37.076636] })const autoOptions
= {city: '全國',input: 'start'}const autoComplete
= new AMap.AutoComplete(autoOptions
)const autoOptions2
= {city: '全國',input: 'end'}const autoComplete2
= new AMap.AutoComplete(autoOptions2
)}).catch(e => {console
.log(e
)})}}
}
</script
>
<style scoped
>
#container
{padding:0px
;margin: 0px
;width: 100%;height: 800px
;
}
#panel
{position: fixed
;background
-color
: white
;max
-height
: 90%;overflow
-y
: auto
;top: 10px
;right: 10px
;width: 280px
;
}
#panel
.amap
-call
{background
-color
: #009cf9
;border
-top
-left
-radius
: 4px
;border
-top
-right
-radius
: 4px
;
}
#panel
.amap
-lib
-driving
{border
-bottom
-left
-radius
: 4px
;border
-bottom
-right
-radius
: 4px
;overflow: hidden
;
}
</style
>
總結
以上是生活随笔為你收集整理的vue使用高德地图web端JSAPI 路线规划、搜索提示教程的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。