更新记录

0.1.1(2026-09-06)

改ios sdk为在线引入

0.1.0(2026-09-06)

初始化


平台兼容性

uni-app(4.57)

Vue2 Vue3 Chrome Safari app-vue app-nvue app-nvue插件版本 Android iOS 鸿蒙
× × × × × 0.1.0 5.0 ×
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
× × × × × × × × × × × ×

uni-app x(4.81)

Chrome Safari Android iOS 鸿蒙 微信小程序
× × 5.0 -

其他

多语言 暗黑模式 宽屏模式

XTF 高德地图原生组件

xtf-gaodemapview 是一个适用于 uni-app x 的高德原生地图组件,提供地图展示、相机控制、标记与图形覆盖物、定位、搜索、路线规划、轨迹、计算、截图和离线地图能力。

重要说明

  • 插件 id 与组件名称为 xtf-gaodemapview,原生实现集成高德 AMap SDK,必须申请并配置高德各平台 Key。
  • iOS 采用高德官方标准地图 SDK(MAMapKit),与 Android、Harmony 使用各自平台的原生高德 SDK 保持一致的地图能力,功能完整但体积较大。
  • 若需在 iOS 端减少包体积,可使用轻量版本https://ext.dcloud.net.cn/plugin?name=xtf-amapview
  • 支持 Android、iOS 和 Harmony。Harmony 当前仅验证地图展示、相机、交通、定位、总手势、UI 控件、覆盖物(点/线/面/圆、热力图、海量点、平滑移动)、缩放/边界、自定义样式、天气;搜索、路线、截图、坐标转换、离线地图等能力会触发 featureunavailable 事件。
  • 标准 uni-app x 页面使用 <xtf-gaodemapview>;nvue 兼容页面使用 <xtf-gaodemapview-nvue>
  • 经纬度数组一律按 [latitude, longitude, latitude, longitude] 成对传入,坐标系参数可选 gcj02wgs84bd09
  • 搜索、路线、截图、计算、离线地图等异步调用不返回 Promise,结果由对应组件事件返回。

安装

将本插件放入项目的 uni_modules/xtf-gaodemapview 目录。组件符合 easycom 目录约定,标准 uvue 页面无需手工注册。

最低版本要求:HBuilderX 5.24.0,uni-app x 4.61.0

配置 Key

在应用启动阶段调用 setAMapKeys。参数顺序固定为 Android、iOS、Harmony 的高德 Key,三个参数均为字符串;暂不使用的平台传空字符串。

// App.uvue
<script setup lang="uts">
import { setAMapKeys, setAMapTerrainEnabled } from "@/uni_modules/xtf-gaodemapview/common/amap-settings.uts"

onLaunch(() => {
  setAMapKeys(
    "YOUR_ANDROID_AMAP_KEY",
    "YOUR_IOS_AMAP_KEY",
    "YOUR_HARMONY_AMAP_KEY"
  )

  // 可选:是否启用地形图层,默认 false。
  setAMapTerrainEnabled(false)
})
</script>
函数 参数 说明 示例
setAMapKeys androidKey, iosKey, harmonyKey: string 设置三个原生平台的高德 Key;必须在地图创建前调用。 setAMapKeys("android", "ios", "harmony")
setAMapTerrainEnabled enabled: boolean 设置 Android/iOS 创建地图时是否启用地形。 setAMapTerrainEnabled(true)
getAMapKeys 获取当前已设置的 Key。 const keys = getAMapKeys()
getAMapTerrainEnabled 获取地形开关状态。 const enabled = getAMapTerrainEnabled()

Android、iOS、Harmony 的签名、包名和高德控制台 Key 白名单需要正确匹配。Harmony 已声明网络与定位权限;Android 和 iOS 仍需按应用自身的隐私合规要求配置定位用途说明与权限。

标准 uvue 快速开始

ref 使用 ComponentPublicInstance,通过 $callMethod 调用暴露方法。地图创建完成后才调用方法,因此应从 ready 回调开始操作。

<template>
  <view class="page">
    <xtf-gaodemapview
      ref="mapRef"
      class="map"
      :camera-latitude="39.90923"
      :camera-longitude="116.397428"
      :camera-zoom="13"
      :my-location-enabled="true"
      @ready="onReady"
      @mapclick="onMapClick"
      @locationchange="onLocationChange"
      @featureunavailable="onUnavailable"
    ></xtf-gaodemapview>
  </view>
</template>

<script setup lang="uts">
type MapDetail = UTSJSONObject

const mapRef = ref<ComponentPublicInstance | null>(null)

function onReady(event: UniNativeViewEvent): void {
  mapRef.value?.$callMethod("addMarker", "tiananmen", 39.90923, 116.397428, "天安门", "地图已就绪", false)
}

function onMapClick(event: UniNativeViewEvent): void {
  const detail = event.detail as MapDetail
  console.log(detail["latitude"] as number, detail["longitude"] as number)
}

function onLocationChange(event: UniNativeViewEvent): void {
  console.log(event.detail["accuracy"] as number)
}

function onUnavailable(event: UniNativeViewEvent): void {
  console.warn(event.detail["feature"] as string, event.detail["message"] as string)
}
</script>

<style>
.page {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.map {
  flex: 1;
  width: 100%;
}
</style>

nvue 快速开始

nvue 使用独立组件名 <xtf-gaodemapview-nvue>。它使用 Options API,公开方法通过 $refs.map 调用。nvue 的属性类公开方法均为 apply*,其余方法名称与 uvue 一致。

<template>
  <div class="page">
    <xtf-gaodemapview-nvue
      ref="map"
      class="map"
      :camera-latitude="39.90923"
      :camera-longitude="116.397428"
      :camera-zoom="13"
      @ready="onReady"
      @markerclick="onMarkerClick"
      @featureunavailable="onUnavailable"
    />
  </div>
</template>

<script>
export default {
  methods: {
    onReady() {
      this.$refs.map.addMarker("tiananmen", 39.90923, 116.397428, "天安门", "nvue 示例", false)
      this.$refs.map.applyTrafficEnabled(true)
    },
    onMarkerClick(event) {
      console.log(event.detail.id)
    },
    onUnavailable(event) {
      console.warn(event.detail.feature, event.detail.message)
    }
  }
}
</script>

<style>
.page {
  flex: 1;
  flex-direction: column;
}

.map {
  flex: 1;
}
</style>

组件参数

所有参数都可在运行中通过响应式绑定更新。camera-* 更新会移动地图;其余开关同步到原生地图。

属性 类型 默认值 说明 示例
camera-latitude number 39.90923 相机中心纬度。 :camera-latitude="39.90923"
camera-longitude number 116.397428 相机中心经度。 :camera-longitude="116.397428"
camera-zoom number 12 缩放级别。 :camera-zoom="15"
camera-tilt number 0 倾斜角。 :camera-tilt="30"
camera-bearing number 0 朝向角。 :camera-bearing="90"
map-type normal \| satellite \| night \| navi normal 地图类型。 map-type="satellite"
traffic-enabled boolean false 是否显示实时交通。 :traffic-enabled="true"
indoor-map-enabled boolean false 是否启用室内地图。 :indoor-map-enabled="true"
world-map-enabled boolean false 是否启用世界地图。 :world-map-enabled="true"
labels-enabled boolean true 是否显示地图文字标注。 :labels-enabled="false"
buildings-enabled boolean true 是否显示建筑物。 :buildings-enabled="false"
my-location-enabled boolean false 是否显示当前位置蓝点;Android 会请求精确定位权限。 :my-location-enabled="true"
gestures-enabled boolean true 总手势开关。 :gestures-enabled="false"
scroll-gestures-enabled boolean true 平移手势开关。 :scroll-gestures-enabled="false"
zoom-gestures-enabled boolean true 缩放手势开关。 :zoom-gestures-enabled="false"
rotate-gestures-enabled boolean true 旋转手势开关。 :rotate-gestures-enabled="false"
tilt-gestures-enabled boolean true 倾斜手势开关。 :tilt-gestures-enabled="false"
custom-map-style string "" 高德自定义地图样式 id。 custom-map-style="amap://styles/xxx"
min-zoom number 未设置 最小缩放级别;必须和 max-zoom 同时传入。 :min-zoom="5"
max-zoom number 未设置 最大缩放级别;必须和 min-zoom 同时传入。 :max-zoom="18"
zoom-controls-enabled boolean true 是否显示缩放控件。 :zoom-controls-enabled="false"
compass-enabled boolean true 是否显示指南针。 :compass-enabled="false"
scale-controls-enabled boolean true 是否显示比例尺。 :scale-controls-enabled="false"
my-location-button-enabled boolean false 是否显示定位按钮。 :my-location-button-enabled="true"

事件

事件参数在 uvue 中为 UniNativeViewEvent,从 event.detail 取值;nvue 中同样通过 event.detail 获取。errorCode0 通常表示成功,具体高德错误码请以 SDK 返回为准。

事件 detail 主要字段 触发时机
ready 原生地图初始化完成。
mapclick latitude, longitude 点击地图。
markerclick id 点击标记。
markerdragstart / markerdrag / markerdragend id, latitude, longitude 拖拽标记。
infowindowclick id 点击标记信息窗。
polylineclick id 点击带 id 的折线。
locationchange latitude, longitude, accuracy 定位蓝点位置更新。
locationerror errorCode, message 定位失败或无权限。
camerachange latitude, longitude, zoom, finished 相机移动中或结束。
poisearch pois, pageCount/totalCount, errorCode, errorMessage? POI 搜索完成(仅 Android/iOS)。
inputtips tips, totalCount, errorCode, errorMessage? 输入提示完成(仅 Android/iOS)。
regeocode formattedAddress, country, province, city, district, township, adCode, latitude, longitude, errorCode 逆地理编码完成(仅 Android/iOS)。
busstopsearch stops, pageCount/totalCount, errorCode 公交站搜索完成(仅 Android/iOS)。
buslinesearch lines, pageCount/totalCount, errorCode 公交线路搜索完成(仅 Android/iOS)。
districtsearch districts, errorCode, errorMessage? 行政区查询完成(仅 Android/iOS)。
weatherquery city, adCode, weather, temperature, windDirection, windPower, humidity, reportTime, errorCode 天气查询完成。
routeplan mode, distance, duration, coordinates, errorCode 路线规划完成(仅 Android/iOS)。
truckrouteplan distance, duration, tolls, tollDistance, trafficLights, coordinates, errorCode 货车路线规划完成(仅 Android/iOS)。
trackcorrect coordinates, distance, duration, errorCode 轨迹纠偏完成。
smoothmove Android 为 errorCode;iOS 为 finished, errorCode 平滑移动结束。
distancecalculate distance, errorCode 距离计算完成(仅 Android/iOS)。
rectangleareacalculate area, errorCode 矩形面积计算完成。
snapshot path, errorCode/errorMessage 截图完成(仅 Android/iOS)。
coordinateconvert source, target, latitude, longitude, errorCode/errorMessage 坐标转换完成(仅 Android/iOS)。
offlinemapready iOS 额外有 success 离线地图初始化完成(仅 Android/iOS)。
offlinemapregions regions 可下载或已下载区域列表返回(仅 Android/iOS)。
offlinemapprogress adCode, status, progress, errorCode, message 离线地图下载、暂停、删除或更新状态变化(仅 Android/iOS)。
featureunavailable feature, message 当前平台未实现或未验证调用能力,Harmony 常见。

方法调用约定

以下表格的 map 代号:

  • uvuemapRef.value?.$callMethod("方法名", ...参数)
  • nvuethis.$refs.map.方法名(...参数)
  • 带星号 * 的属性类方法在 nvue 应使用右侧对应的 apply* 名称;uvue 保持左侧方法名。

地图与交互方法

uvue 方法 参数与说明 uvue 调用示例 nvue 对应调用
setCamera latitude, longitude, zoom, tilt, bearing, animated=true:移动相机。 mapRef.value?.$callMethod("setCamera", 39.90923, 116.397428, 15, 0, 0, true) this.$refs.map.setCamera(39.90923, 116.397428, 15, 0, 0)
setMapType* normal \| satellite \| night \| navi:切换类型。 mapRef.value?.$callMethod("setMapType", "satellite") this.$refs.map.applyMapType("satellite")
setTrafficEnabled* enabled:交通图层。 mapRef.value?.$callMethod("setTrafficEnabled", true) this.$refs.map.applyTrafficEnabled(true)
setIndoorMapEnabled* enabled:室内地图。 mapRef.value?.$callMethod("setIndoorMapEnabled", true) this.$refs.map.applyIndoorMapEnabled(true)
setWorldMapEnabled* enabled:世界地图。 mapRef.value?.$callMethod("setWorldMapEnabled", true) this.$refs.map.applyWorldMapEnabled(true)
setLabelsEnabled* enabled:文字标注。 mapRef.value?.$callMethod("setLabelsEnabled", false) this.$refs.map.applyLabelsEnabled(false)
setBuildingsEnabled* enabled:建筑物。 mapRef.value?.$callMethod("setBuildingsEnabled", false) this.$refs.map.applyBuildingsEnabled(false)
setMyLocationEnabled* enabled:定位蓝点;处理 locationchangelocationerror mapRef.value?.$callMethod("setMyLocationEnabled", true) this.$refs.map.applyMyLocationEnabled(true)
setGesturesEnabled* enabled:总手势。 mapRef.value?.$callMethod("setGesturesEnabled", false) this.$refs.map.applyGesturesEnabled(false)
setScrollGesturesEnabled* enabled:平移手势。 mapRef.value?.$callMethod("setScrollGesturesEnabled", false) this.$refs.map.applyScrollGesturesEnabled(false)
setZoomGesturesEnabled* enabled:缩放手势。 mapRef.value?.$callMethod("setZoomGesturesEnabled", false) this.$refs.map.applyZoomGesturesEnabled(false)
setRotateGesturesEnabled* enabled:旋转手势。 mapRef.value?.$callMethod("setRotateGesturesEnabled", false) this.$refs.map.applyRotateGesturesEnabled(false)
setTiltGesturesEnabled* enabled:倾斜手势。 mapRef.value?.$callMethod("setTiltGesturesEnabled", false) this.$refs.map.applyTiltGesturesEnabled(false)
setCustomMapStyle* styleId:高德自定义样式 id。 mapRef.value?.$callMethod("setCustomMapStyle", "amap://styles/xxx") this.$refs.map.applyCustomMapStyle("amap://styles/xxx")
setZoomRange minZoom, maxZoom:缩放范围。 mapRef.value?.$callMethod("setZoomRange", 5, 18) this.$refs.map.setZoomRange(5, 18)
setBounds swLat, swLng, neLat, neLng:相机适配范围。 mapRef.value?.$callMethod("setBounds", 39.8, 116.2, 40.0, 116.5) this.$refs.map.setBounds(39.8, 116.2, 40.0, 116.5)
setUiSettings zoomControls, compass, scale, locationButton:原生控件。 mapRef.value?.$callMethod("setUiSettings", true, true, true, false) this.$refs.map.setUiSettings(true, true, true, false)

标记方法

方法 参数与说明 uvue 调用示例 nvue 调用示例
addMarker id, latitude, longitude, title, snippet, draggable:添加标记。 mapRef.value?.$callMethod("addMarker", "home", 39.9, 116.4, "家", "北京", false) this.$refs.map.addMarker("home", 39.9, 116.4, "家", "北京", false)
updateMarker addMarker 相同:更新已有 id 的标记。 mapRef.value?.$callMethod("updateMarker", "home", 39.91, 116.41, "新位置", "已更新", true) this.$refs.map.updateMarker("home", 39.91, 116.41, "新位置", "已更新", true)
removeMarker id:删除标记。 mapRef.value?.$callMethod("removeMarker", "home") this.$refs.map.removeMarker("home")
setMarkerVisible id, visible:显示或隐藏标记。 mapRef.value?.$callMethod("setMarkerVisible", "home", false) this.$refs.map.setMarkerVisible("home", false)
setMarkerAnchor id, anchorX, anchorY:设置锚点,范围通常为 01 mapRef.value?.$callMethod("setMarkerAnchor", "home", 0.5, 1) this.$refs.map.setMarkerAnchor("home", 0.5, 1)
setMarkerAlpha id, alpha:设置透明度,范围 01 mapRef.value?.$callMethod("setMarkerAlpha", "home", 0.7) this.$refs.map.setMarkerAlpha("home", 0.7)
setMarkerFlat id, flat:设置是否贴地。 mapRef.value?.$callMethod("setMarkerFlat", "home", true) this.$refs.map.setMarkerFlat("home", true)
setMarkerRotation id, rotation:设置旋转角度。 mapRef.value?.$callMethod("setMarkerRotation", "home", 45) this.$refs.map.setMarkerRotation("home", 45)
setMarkerIcon id, iconPath:设置图标路径。 mapRef.value?.$callMethod("setMarkerIcon", "home", "/static/marker.png") this.$refs.map.setMarkerIcon("home", "/static/marker.png")
showInfoWindow id:显示信息窗。 mapRef.value?.$callMethod("showInfoWindow", "home") this.$refs.map.showInfoWindow("home")
hideInfoWindow id:隐藏信息窗。 mapRef.value?.$callMethod("hideInfoWindow", "home") this.$refs.map.hideInfoWindow("home")

图形覆盖物方法

方法 参数与说明 uvue 调用示例 nvue 调用示例
addPolyline coordinates, color, width:添加无 id 折线。 mapRef.value?.$callMethod("addPolyline", [39.9, 116.3, 39.91, 116.4], "#1677ff", 6) this.$refs.map.addPolyline([39.9, 116.3, 39.91, 116.4], "#1677ff", 6)
addPolylineWithId id, coordinates, color, width, dotted, visible, clickable:添加可管理折线。 mapRef.value?.$callMethod("addPolylineWithId", "route", [39.9, 116.3, 39.91, 116.4], "#1677ff", 6, false, true, true) this.$refs.map.addPolylineWithId("route", [39.9, 116.3, 39.91, 116.4], "#1677ff", 6, false, true, true)
updatePolyline id, coordinates, color, width, dotted:更新折线。 mapRef.value?.$callMethod("updatePolyline", "route", [39.9, 116.3, 39.92, 116.42], "#f5222d", 8, true) this.$refs.map.updatePolyline("route", [39.9, 116.3, 39.92, 116.42], "#f5222d", 8, true)
removePolyline id:删除折线。 mapRef.value?.$callMethod("removePolyline", "route") this.$refs.map.removePolyline("route")
setPolylineVisible id, visible:显示或隐藏折线。 mapRef.value?.$callMethod("setPolylineVisible", "route", false) this.$refs.map.setPolylineVisible("route", false)
setPolylineClickable id, clickable:设置折线点击。 mapRef.value?.$callMethod("setPolylineClickable", "route", true) this.$refs.map.setPolylineClickable("route", true)
addPolygon coordinates, strokeColor, fillColor, strokeWidth:添加多边形。 mapRef.value?.$callMethod("addPolygon", [39.9, 116.3, 39.9, 116.4, 39.95, 116.35], "#1677ff", "#401677ff", 2) this.$refs.map.addPolygon([39.9, 116.3, 39.9, 116.4, 39.95, 116.35], "#1677ff", "#401677ff", 2)
addCircle latitude, longitude, radius, strokeColor, fillColor, strokeWidth:半径单位米。 mapRef.value?.$callMethod("addCircle", 39.90923, 116.397428, 500, "#1677ff", "#401677ff", 2) this.$refs.map.addCircle(39.90923, 116.397428, 500, "#1677ff", "#401677ff", 2)
clearOverlays 无:清除插件创建的覆盖物。 mapRef.value?.$callMethod("clearOverlays") this.$refs.map.clearOverlays()
setHeatPoints coordinates, intensities, radius, opacity:热力点及强度。 mapRef.value?.$callMethod("setHeatPoints", [39.9, 116.3, 39.91, 116.4], [1, 5], 30, 0.8) this.$refs.map.setHeatPoints([39.9, 116.3, 39.91, 116.4], [1, 5], 30, 0.8)
setClusterPoints coordinates, ids, titles, snippets, minClusterSize:聚合点。 mapRef.value?.$callMethod("setClusterPoints", [39.9, 116.3, 39.91, 116.4], ["a", "b"], ["A", "B"], ["", ""], 2) this.$refs.map.setClusterPoints([39.9, 116.3, 39.91, 116.4], ["a", "b"], ["A", "B"], ["", ""], 2)
setMassPoints coordinates, pointSize, color, iconPath, opacity:海量点。 mapRef.value?.$callMethod("setMassPoints", [39.9, 116.3, 39.91, 116.4], 8, "#1677ff", "", 0.8) this.$refs.map.setMassPoints([39.9, 116.3, 39.91, 116.4], 8, "#1677ff", "", 0.8)

搜索、路线与工具方法

以下方法在鸿蒙端不可用,仅 Android 与 iOS 支持;鸿蒙端调用会触发 featureunavailable

调用下列方法后,在组件上监听表中对应事件取得异步结果。

方法 参数与说明 uvue 调用示例 nvue 调用示例 结果事件
searchPoi keyword, city, page=0, pageSize=20:POI 搜索。 mapRef.value?.$callMethod("searchPoi", "天安门", "北京", 0, 20) this.$refs.map.searchPoi("天安门", "北京", 0, 20) poisearch
searchPoiNearbyCircle keyword, city, latitude, longitude, radius, page=0, pageSize=20:圆形周边 POI 搜索。 mapRef.value?.$callMethod("searchPoiNearbyCircle", "餐厅", "北京", 39.9, 116.4, 1000, 0, 20) this.$refs.map.searchPoiNearbyCircle("餐厅", "北京", 39.9, 116.4, 1000, 0, 20) poisearch
searchPoiNearbyRectangle keyword, city, southwestLatitude, southwestLongitude, northeastLatitude, northeastLongitude, page=0, pageSize=20:矩形周边 POI 搜索。 mapRef.value?.$callMethod("searchPoiNearbyRectangle", "餐厅", "北京", 39.8, 116.3, 40.0, 116.5, 0, 20) this.$refs.map.searchPoiNearbyRectangle("餐厅", "北京", 39.8, 116.3, 40.0, 116.5, 0, 20) poisearch
searchPoiNearbyPolygon keyword, city, coordinates, page=0, pageSize=20:多边形周边 POI 搜索,坐标按纬度、经度交替传入。 mapRef.value?.$callMethod("searchPoiNearbyPolygon", "餐厅", "北京", [39.8, 116.3, 39.8, 116.5, 40.0, 116.5], 0, 20) this.$refs.map.searchPoiNearbyPolygon("餐厅", "北京", [39.8, 116.3, 39.8, 116.5, 40.0, 116.5], 0, 20) poisearch
requestInputTips keyword, city="", cityLimit=false:输入提示。 mapRef.value?.$callMethod("requestInputTips", "天安", "北京", true) this.$refs.map.requestInputTips("天安", "北京", true) inputtips
reverseGeocode latitude, longitude, radius=1000, extensions="base":逆地理编码。 mapRef.value?.$callMethod("reverseGeocode", 39.90923, 116.397428, 1000, "base") this.$refs.map.reverseGeocode(39.90923, 116.397428, 1000, "base") regeocode
searchBusStop keyword, city, page=0, pageSize=20:公交站搜索。 mapRef.value?.$callMethod("searchBusStop", "天安门", "北京", 0, 20) this.$refs.map.searchBusStop("天安门", "北京", 0, 20) busstopsearch
searchBusLine keyword, city, page=0, pageSize=20:公交线搜索。 mapRef.value?.$callMethod("searchBusLine", "1路", "北京", 0, 20) this.$refs.map.searchBusLine("1路", "北京", 0, 20) buslinesearch
searchDistrict keyword, subDistrict=0, extensions="base":行政区查询。 mapRef.value?.$callMethod("searchDistrict", "北京市", 0, "base") this.$refs.map.searchDistrict("北京市", 0, "base") districtsearch
queryWeather city, weatherType="live":天气查询。 mapRef.value?.$callMethod("queryWeather", "北京", "live") this.$refs.map.queryWeather("北京", "live") weatherquery
planRoute mode, startLat, startLng, endLat, endLng, cityCode=""modedrivingwalkingridingtransit mapRef.value?.$callMethod("planRoute", "driving", 39.90923, 116.397428, 39.91498, 116.40531, "北京") this.$refs.map.planRoute("driving", 39.90923, 116.397428, 39.91498, 116.40531, "北京") routeplan
planTruckRoute startLat, startLng, endLat, endLng, waypoints, strategy=0, truckType=0, truckSize=0, truckHeight=0, truckWidth=0, truckLength=0, truckLoad=0, truckWeight=0, truckAxleWeight=0, truckAxleCount=0, isVehicle=false:货车路径。 mapRef.value?.$callMethod("planTruckRoute", 39.9, 116.3, 39.95, 116.4, [], 0, 0, 0, 0, 0, 0, 0, 0, 0, false) this.$refs.map.planTruckRoute(39.9, 116.3, 39.95, 116.4, [], 0, 0, 0, 0, 0, 0, 0, 0, 0, false) truckrouteplan
correctTrack coordinates, coordinateSystem="gcj02", mode="driving":轨迹纠偏。 mapRef.value?.$callMethod("correctTrack", [39.9, 116.3, 39.91, 116.4], "gcj02", "driving") this.$refs.map.correctTrack([39.9, 116.3, 39.91, 116.4], "gcj02", "driving") trackcorrect
smoothMove startLat, startLng, coordinates, duration:沿路径平滑移动,时长单位毫秒。 mapRef.value?.$callMethod("smoothMove", 39.9, 116.3, [39.91, 116.4], 3000) this.$refs.map.smoothMove(39.9, 116.3, [39.91, 116.4], 3000) smoothmove
calculateDistance coordinates:按连续点计算总距离。 mapRef.value?.$callMethod("calculateDistance", [39.9, 116.3, 39.91, 116.4]) this.$refs.map.calculateDistance([39.9, 116.3, 39.91, 116.4]) distancecalculate
calculateRectangleArea swLat, swLng, neLat, neLng:计算矩形面积。 mapRef.value?.$callMethod("calculateRectangleArea", 39.8, 116.2, 40.0, 116.5) this.$refs.map.calculateRectangleArea(39.8, 116.2, 40.0, 116.5) rectangleareacalculate
takeSnapshot 无:生成当前地图截图。 mapRef.value?.$callMethod("takeSnapshot") this.$refs.map.takeSnapshot() snapshot
convertCoordinate latitude, longitude, source, target:坐标转换。 mapRef.value?.$callMethod("convertCoordinate", 39.9, 116.3, "wgs84", "gcj02") this.$refs.map.convertCoordinate(39.9, 116.3, "wgs84", "gcj02") coordinateconvert

离线地图方法

离线地图与下载功能在鸿蒙端不可用,仅 Android 与 iOS 支持;鸿蒙端调用会触发 featureunavailable

离线地图应遵循:ready 后调用 initializeOfflineMap,收到 offlinemapready 后调用 listOfflineMapRegions,随后选择 adCode 下载。状态变化通过 offlinemapprogress 返回。

方法 参数与说明 uvue 调用示例 nvue 调用示例 结果事件
initializeOfflineMap 无:初始化离线服务。 mapRef.value?.$callMethod("initializeOfflineMap") this.$refs.map.initializeOfflineMap() offlinemapready
listOfflineMapRegions 无:列出可下载区域。 mapRef.value?.$callMethod("listOfflineMapRegions") this.$refs.map.listOfflineMapRegions() offlinemapregions
listDownloadedOfflineMaps 无:列出已下载区域。 mapRef.value?.$callMethod("listDownloadedOfflineMaps") this.$refs.map.listDownloadedOfflineMaps() offlinemapregions
downloadOfflineMap adCode:下载区域,例如北京为 110000 mapRef.value?.$callMethod("downloadOfflineMap", "110000") this.$refs.map.downloadOfflineMap("110000") offlinemapprogress
pauseOfflineMap adCode:暂停下载。 mapRef.value?.$callMethod("pauseOfflineMap", "110000") this.$refs.map.pauseOfflineMap("110000") offlinemapprogress
removeOfflineMap adCode:删除离线包。 mapRef.value?.$callMethod("removeOfflineMap", "110000") this.$refs.map.removeOfflineMap("110000") offlinemapprogress
checkOfflineMapUpdates 无:检查更新。 mapRef.value?.$callMethod("checkOfflineMapUpdates") this.$refs.map.checkOfflineMapUpdates() offlinemapprogress
openOfflineMapManager 无:打开原生离线地图管理页。 mapRef.value?.$callMethod("openOfflineMapManager") this.$refs.map.openOfflineMapManager() 平台原生界面

平台能力差异

能力 Android iOS Harmony
地图、相机、交通、总手势、UI 控件 支持 支持 支持
定位蓝点 支持 支持 支持
点、线、面、圆 支持 支持 支持
单项手势、缩放范围、边界、自定义样式 支持 支持 支持
标记细节、线显示/点击 支持 支持 支持
热力图、海量点、平滑移动、天气 支持 支持 支持
搜索(POI、输入提示、逆地理、公交站、公交线、行政区、距离) 支持 支持 不可用
路线(驾车/步行/骑行/公交、货车) 支持 支持 不可用
截图、坐标转换 支持 支持 不可用
离线地图与下载 支持 支持 不可用
线可点击、聚合点、轨迹纠偏、矩形面积、世界地图 支持 支持 不可用

搜索、路线规划、截图、坐标转换、离线地图与下载在鸿蒙端不可用,仅 Android 与 iOS 支持;鸿蒙端调用会触发 featureunavailable

Harmony 端当前支持:地图/相机/交通/总手势/单项手势/UI 控件/定位/覆盖物、缩放范围、地图边界、自定义样式、地图文字/建筑/室内、标记(可见/锚点/透明度/贴地/旋转/图标/信息窗)、线显隐、热力图、海量点、平滑移动、天气。

建议所有页面监听 featureunavailable,并用 detail.feature 区分能力。这比按平台名称静态分支更可靠,因为它反映的是当前插件实际已验证的能力。

完整异步处理示例

<xtf-gaodemapview
  ref="mapRef"
  class="map"
  @ready="onReady"
  @poisearch="onPoiSearch"
  @routeplan="onRoutePlan"
  @snapshot="onSnapshot"
  @featureunavailable="onUnavailable"
></xtf-gaodemapview>
function onReady(event: UniNativeViewEvent): void {
  mapRef.value?.$callMethod("searchPoi", "天安门", "北京", 0, 10)
}

function onPoiSearch(event: UniNativeViewEvent): void {
  const pois = event.detail["pois"] as Array<UTSJSONObject>
  if (pois.length > 0) {
    const firstPoi = pois[0]
    mapRef.value?.$callMethod(
      "setCamera",
      firstPoi["latitude"] as number,
      firstPoi["longitude"] as number,
      16,
      0,
      0,
      true
    )
  }
}

function onRoutePlan(event: UniNativeViewEvent): void {
  const coordinates = event.detail["coordinates"] as Array<number>
  mapRef.value?.$callMethod("addPolylineWithId", "route", coordinates, "#1677ff", 6, false, true, true)
}

function onSnapshot(event: UniNativeViewEvent): void {
  const path = event.detail["path"] as string
  console.log("地图截图:" + path)
}

function onUnavailable(event: UniNativeViewEvent): void {
  console.warn("能力不可用:" + (event.detail["feature"] as string))
}

常见问题

地图空白或未触发 ready

确认 setAMapKeys 已在 App.uvueonLaunch 中执行,平台 Key、包名、签名与高德控制台配置一致,并已重新构建原生应用。

定位没有结果

确认传入 my-location-enabled 或在 ready 后调用 setMyLocationEnabled(true),并处理 locationerror。用户拒绝权限时组件会返回错误事件。

Harmony 收到 featureunavailable

这是已知平台能力状态。读取 event.detail.feature 后提供降级界面,或仅在 Android/iOS 使用该能力;不要假设未验证能力可用。

调用方法没有效果

确认调用发生在 ready 之后。标准 uvue 必须使用 $callMethod,nvue 必须使用 $refs.map,且 nvue 的属性类方法应使用 apply* 名称。

隐私、权限声明

1. 本插件需要申请的系统权限列表:

网络权限、定位权限。仅在启用地图或定位功能时使用。

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件本身不采集数据。高德 AMap SDK 可能处理定位和设备信息以提供地图与定位服务。

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。