更新记录
1.0.1(2024-04-09)
解决由于坐标系不匹配的导致定位不准的问题。
1.0.0(2023-11-14)
首个版本发布。
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
× |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
组件功能
在高德地图上显示数据的marker和用户当前位置的marker。
文档
属性说明
属性名 |
类型 |
默认值 |
说明 |
markers |
Array |
[] |
地图标注列表,下面有详细说明 |
geo |
Object |
null |
用户自动定位标注,下面有详细说明 |
mapId |
String |
'location' + Date.now() |
地图容器id |
mapWidth |
String, Number |
100% |
地图容器宽度 |
mapHeight |
String, Number |
100% |
地图容器高度 |
useJscode |
Boolean |
true |
是否启用高德安全密钥jscode,默认启用 |
serviceHost |
String |
'' |
代理服务器域名或地址,useJscode为true时生效 |
amapKey |
String |
|
申请的高德地图Web端的key值,必传 |
@current-positon |
EventHandle |
|
用户当前位置自动定位成功时触发,参数是一个GeolocationResult 对象 |
markers 数组元素属性说明
markers 的每个元素必须是一个对象且有下列属性:
属性名 |
类型 |
默认值 |
说明 |
lng |
String, Number |
|
经度 |
lat |
String, Number |
|
纬度 |
icon |
String |
高德默认marker图标 |
标注的图标url,可以线上url, 也可以是本地url;当是本地url时,要注意区分H5端和APP端的写法:以static文件夹为例,H5端以“/static”开头,而APP端则以“static”开头 |
width |
Number |
图标原始宽度 |
图标宽度,单位:px |
height |
Number |
图标原始宽度 |
图标宽度,单位:px |
anchor |
String |
center |
图标锚点位置,可选值:'top-left'/'top-center'/'top-right'/'middle-left'/'center'/'middle-right'/'bottom-left'/'bottom-center'/'bottom-right' |
geo 对象属性说明
属性名 |
类型 |
默认值 |
说明 |
icon |
String |
高德默认定位图标 |
定位图标url,可以线上url, 也可以是本地url;当是本地url时,要注意区分H5端和APP端的写法:以static文件夹为例,H5端以“/static”开头,而APP端则以“static”开头 |
width |
Number |
定位图标原始宽度 |
定位图标宽度,单位:px |
height |
Number |
定位图标原始宽度 |
定位图标宽度,单位:px |
anchor |
String |
center |
定位图标锚点位置,可选值:'top-left'/'top-center'/'top-right'/'middle-left'/'center'/'middle-right'/'bottom-left'/'bottom-center'/'bottom-right' |
示例代码
<!-- 高德地图定位标注 -->
<template>
<view class="map-location">
<lk-amap-location
amap-key="daa29f45bd22dab89187ec700409d1ed"
service-host="http://localhost:8888/"
:markers="list"
@current-positon="getPosition"
></lk-amap-location>
</view>
</template>
<script setup>
import { ref } from 'vue'
const list = ref([])
const location = ref({})
const geo = {
// #ifdef APP-PLUS
icon: 'static/img/map/position.png',
// #endif
// #ifdef H5
icon: '/static/img/map/position.png',
// #endif
width: 20,
height: 20
}
const loadData = () => {
list.value = Array.from({length: 10}, () => ({
lng: (Math.random() * (135.083 - 73.55 + 1) + 73.55).toFixed(6), // 随机经度,
lat: (Math.random() * (53.55 - 3.85 + 1) + 3.85).toFixed(6), // 随机纬度,
icon: 'https://source.unsplash.com/random/?car', // 随机车辆图片
width: 30,
height: 30,
anchor: 'bottom-center'
}))
}
loadData()
const getPosition = info => location.value = info
</script>
<style lang="scss">
.map-location {
height: 100%;
}
</style>
在线演示
在线演示地址
其他
组件难免有不足之处,欢迎各位老铁们批评指正,有任何问题都可以在评论区中留言。