更新记录

0.3.0(2026-07-13) 下载此版本

免费

0.2.0(2026-07-13) 下载此版本

初始发布:全平台天地图 WebView 地图组件,支持标记点、定位、聚合、卫星/标准图切换


平台兼容性

uni-app(4.24)

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

@geek-fun/uni-map

[![CI](https://github.com/geek-fun/geekfun-uni-map/actions/workflows/ci.yml/badge.svg)](https://github.com/geek-fun/geekfun-uni-map/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) **一套地图 API,全平台通用。** uni-app 跨平台地图组件。当前全平台使用天地图 WebView,鸿蒙花瓣地图原生渲染代码已就绪,等待 HBuilderX 修复 `<embed>` 组件 bug 后启用。 [GitHub](https://github.com/geek-fun/geekfun-uni-map) • [Issues](https://github.com/geek-fun/geekfun-uni-map/issues)

平台支持

平台 地图服务 渲染方式 状态
HarmonyOS NEXT 天地图 WebView ✅ 可用
Android 天地图 WebView ✅ 可用
iOS 天地图 WebView ✅ 可用
H5 天地图 WebView ✅ 可用
HarmonyOS (原生) ⏳ 花瓣地图 (Map Kit) 原生 ArkUI ⏸️ 受阻

当前版本: 0.2.0 — 早期发布,API 可能变化。


快速开始

1. 安装

通过 HBuilderX 插件市场导入 geekfun-uni-map

  1. 打开 HBuilderX
  2. 点击顶部菜单 [插件] → [浏览插件市场]
  3. 搜索 geekfun-uni-map
  4. 点击"导入插件"

2. 申请天地图 Key

  1. lbs.tianditu.gov.cn 注册账号
  2. 创建 浏览器端 (Browser) 应用
  3. 复制 API Key(tk 值)

当前所有平台都使用天地图,都需要 Key。

3. 使用组件

<template>
  <MapView
    :options="mapOptions"
    @ready="onReady"
    @markertap="onMarkerTap"
    @error="onError"
  />
</template>

<script setup lang="ts">
import MapView from '@geek-fun/uni-map'
import type { MapOptions } from '@geek-fun/uni-map'

const mapOptions: MapOptions = {
  latitude: 39.9,
  longitude: 116.4,
  zoom: 12,
  mapType: 'STANDARD',
  tiandituKey: 'your_tianditu_browser_key',  // 天地图浏览器端 Key
  showMyLocation: true,
}

function onReady() {
  console.log('Map ready')
}

function onMarkerTap(e: { markerId: string | number }) {
  console.log('Marker tapped:', e.markerId)
}

function onError(e: { code: string; message: string }) {
  console.error('Map error:', e.message)
}
</script>

4. HarmonyOS:注册原生组件

App.vue 中添加副作用导入(在任何 <embed> 标签渲染之前):

// App.vue
import '@geek-fun/uni-map'

这会触发 defineNativeEmbed('geekfun-map'),注册原生地图组件。


API 参考

Props

组件只接受一个 options prop,类型为 MapOptions

Events

事件 载荷 说明
ready MapReadyEvent 地图加载完成,可交互
markertap MarkerTapEvent 用户点击了标记点
opendetail { trailId: string } 用户点击信息窗口的"查看详情"
userlocation { latitude, longitude } WebView 上报用户 GPS 位置
dismissselection void 用户点击地图空白处
error { code: string; message: string } 发生错误(SDK 加载失败、Key 缺失等)

外部方法(通过 ref

<MapView ref="mapRef" :options="mapOptions" />
const mapRef = ref<MapContext>()

// 飞行到指定位置
mapRef.value?.flyTo(24.65, 102.6, 15)

// 替换所有标记点
mapRef.value?.setMarkers([{ id: 1, latitude: 24.65, longitude: 102.6, title: 'Sample' }])

// 获取最近已知用户位置
const loc = mapRef.value?.getUserLocation()

// 请求定位并飞往用户位置
await mapRef.value?.requestLocation()

// 切换标准/卫星地图
mapRef.value?.toggleMapType()

TypeScript 类型

MapOptions

字段 类型 必填 默认值 说明
latitude number 中心纬度
longitude number 中心经度
zoom number 12 初始缩放级别 (1-20)
minZoom number 2 最小缩放
maxZoom number 20 最大缩放
mapType 'STANDARD' \| 'SATELLITE' \| 'HYBRID' 'STANDARD' 地图类型
dayNightMode 'DAY' \| 'NIGHT' \| 'AUTO' 日夜间模式(仅鸿蒙)
showMyLocation boolean false 显示我的位置蓝点
showLocateButton boolean true 显示定位按钮
showMapTypeButton boolean true 显示图层切换按钮
markers MarkerOptions[] [] 初始标记点
tiandituKey string ⚠️ 天地图浏览器端 Key(必填)
tileServer TileServerOptions 自定义瓦片代理

MarkerOptions

字段 类型 必填 说明
id number \| string 标记点唯一 ID
latitude number 纬度
longitude number 经度
iconPath string 自定义图标 URL
width number 图标宽度 (px)
height number 图标高度 (px)
title string 气泡标题(鸿蒙上显示)
snippet string 描述文本
riskLevel 'safe' \| 'warning' \| 'danger' \| 'unknown' 风险色
clickable boolean true 是否可点击
data MarkerData 自定义数据

MarkerData

字段 类型 说明
speciesName string 物种显示名称
confidence number 匹配度 (0-100)
photoUrl string 照片缩略图
observedAt string 观察时间戳
[key: string] any 额外自定义字段

TileServerOptions

字段 类型 说明
baseUrl string 瓦片代理基准 URL
urlTemplate string 自定义 URL 模板(默认 {baseUrl}/{z}/{x}/{y}
hasSatellite boolean 代理是否支持卫星瓦片

功能特性

  • 🌐 天地图 WebView — 全平台统一(免费)
  • 🗺️ 花瓣地图原生 — 鸿蒙代码已就绪,等待 HBuilderX bug 修复
  • 📍 内置定位 — 定位按钮 + 加载遮罩反馈
  • 🎯 标记点聚合 — 大数据量下自动聚类
  • 🛰️ 标准/卫星图切换map.setMapType() 内置支持
  • 🎨 风险色标记点 — 自定义信息弹窗
  • 加载遮罩 — 初始化时显示转圈 + 状态文字
  • 参数校验 — 必填字段缺失时显示明确的错误遮罩
  • 🧹 无硬编码 KeytiandituKey 通过 options 运行时传入
  • 🔔 @error 事件 — SDK 加载失败或配置错误的回调

高级:自定义瓦片代理

如果你想通过自己的后端代理天地图瓦片(用于安全或缓存):

const mapOptions: MapOptions = {
  latitude: 39.9,
  longitude: 116.4,
  tiandituKey: 'your_key',
  tileServer: {
    baseUrl: 'https://your-api.com/api/map/tiles',
  },
}

设置 tileServer.baseUrl 后,WebView 会从代理 URL 加载瓦片,而不是直接请求天地图 CDN。


常见问题

地图显示"配置缺失 请传入 tiandituKey"

tiandituKey 是所有平台的必填参数。在 MapOptions 中传入:

const options: MapOptions = {
  latitude: 24.65,
  longitude: 102.6,
  tiandituKey: 'your_tianditu_key',
}

地图空白 / 瓦片不加载(Android/iOS)

  1. 确认天地图 Key 是 浏览器端 (Browser) 类型,不是服务端
  2. 在天地图控制台将域名白名单设为 * 或你的代理域名。移动端没有固定 referrer,推荐 *
  3. 检查设备网络连接是否正常
  4. 如果不能用 *设置瓦片代理 通过自己的域名转发

HarmonyOS:地图白屏

  1. 确保 App.vue 中有 import '@geek-fun/uni-map'(在任何 <embed> 渲染之前执行)
  2. 确认 agconnect-services.json 已正确配置
  3. 确认 AppGallery Connect 中已开启 Map Kit 服务

花瓣地图原生渲染未启用

花瓣地图原生集成代码(utssdk/app-harmony/map.ets)已完整实现,但当前因 HBuilderX 5.07 的 <embed> 组件 bug(nodeRenderType of undefined)而禁用。全平台(含鸿蒙)目前使用天地图 WebView 作为降级方案。原生路径将在 HBuilderX 修复后恢复。

@ready 事件没有触发

组件有一个 6 秒兜底机制:即使 WebView 没有响应也会触发 ready。如果 6 秒后 ready 仍未触发,查看控制台中 [geekfun-map-diag] 相关日志。


License

Apache-2.0

隐私、权限声明

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

ohos.permission.INTERNET, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION

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

插件不采集任何数据。天地图 SDK 会采集位置数据用于地图渲染,详情参考 https://lbs.tianditu.gov.cn

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

许可协议

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

  1. Definitions.

    "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.

    "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.

    "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.

    "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.

    "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.

    "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.

    "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).

    "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.

    "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."

    "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.

  2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.

  3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.

  4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:

    (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and

    (b) You must cause any modified files to carry prominent notices stating that You changed the files; and

    (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and

    (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

    You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.

  5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.

  6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.

  7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.

  8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.

  9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

    END OF TERMS AND CONDITIONS

    APPENDIX: How to apply the Apache License to your work.

    To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.

    Copyright 2026 geekfun

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

暂无用户评论。