高德API使用
# 天气
# web服务
https://lbs.amap.com/api/webservice/guide/api/weatherinfo/
this.$http.get('https://restapi.amap.com/v3/weather/weatherInfo?parameters', {
params: {
city: '天津',
key: '02856674a96113aff907cf0ddf777197',
level: '2',
output: 'JSON',
extensions: 'base'
}
}).then(res => {
if (res.status !== '1') {
this.$toast.fail('获取天气失败')
return
}
this.weather = res.lives[0] || {}
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# JsAPI
https://lbs.amap.com/api/jsapi-v2/guide/services/weather
# 定位
https://lbs.amap.com/api/jsapi-v2/guide/services/geolocation
<script src="https://webapi.amap.com/maps?v=1.4.15&key=f9a21f10e9dd921f182a3cac2c126c95&plugin=AMap.Driving"></script>
1
2
2
return new Promise((resolve, reject) => {
AMap.plugin('AMap.Geolocation', function() {
var geolocation = new AMap.Geolocation({
// 是否使用高精度定位,默认:true
enableHighAccuracy: false,
// 设置定位超时时间,默认:无穷大
timeout: 3000,
// 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20)
buttonOffset: new AMap.Pixel(10, 20),
// 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
zoomToAccuracy: true,
// 定位按钮的排放位置, RB表示右下
buttonPosition: 'RB',
})
geolocation.getCurrentPosition()
AMap.event.addListener(geolocation, 'complete', onComplete)
AMap.event.addListener(geolocation, 'error', onError)
function onComplete(data) {
let tc = new TransCoordinate()
let pointObj = tc.gcj_decrypt_exact(
data.position.lat,
data.position.lng
)
// alert(JSON.stringify(pointObj))
resolve(pointObj)
}
function onError(data) {
resolve({lat:39.08419039899525,lon:117.30027867723375})
}
})
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 路线规划
https://lbs.amap.com/api/jsapi-v2/guide/services/navigation
<script>
window._AMapSecurityConfig = {
securityJsCode: 'df874939743107e5d970d762fb3abc5d',
}
</script>
1
2
3
4
5
2
3
4
5
# 驾车
AMap.plugin('AMap.Driving', () => {
var driving = new AMap.Driving({
// 驾车路线规划策略,AMap.DrivingPolicy.LEAST_TIME是最快捷模式
policy: AMap.DrivingPolicy.LEAST_TIME,
})
driving.search(startLngLat, endLngLat, (status, result) => {
console.log(result)
})
})
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 走路
AMap.plugin('AMap.Walking', () => {
var driving = new AMap.Walking({})
driving.search(startLngLat, endLngLat, (status, result) => {
console.log(result)
})
})
1
2
3
4
5
6
2
3
4
5
6
上次更新: 2022/05/05, 17:47:41