• Stars
    star
    1,262
  • Rank 37,273 (Top 0.8 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

react-native 高德地图组件,使用最新 3D SDK,支持 Android + iOS

react-native-amap3d

注意:该项目目前只维护,不加新功能。

react-native 高德地图组件,使用最新 3D SDK,支持 Android + iOS,受 react-native-maps 启发,提供功能丰富且易用的接口。

相关项目推荐:

功能

  • 地图模式切换(常规、卫星、导航、夜间)
  • 3D 建筑、路况、室内地图
  • 内置地图控件的显示隐藏(指南针、比例尺、定位按钮、缩放按钮)
  • 手势交互控制(平移、缩放、旋转、倾斜)
  • 中心坐标、缩放级别、倾斜度的设置,支持动画过渡
  • 地图事件(onPress、onLongPress、onLocation、onCameraMove、onCameraIdle 等)
  • 地图标记(Marker)
  • 折线绘制(Polyline)
  • 多边形绘制(Polygon)
  • 圆形绘制(Circle)
  • 热力图(HeatMap)
  • 海量点(MultiPoint)
  • 点聚合(Cluster)

接口文档

https://qiuxiang.github.io/react-native-amap3d/api/

安装

npm i react-native-amap3d

添加高德 API Key

首先你需要获取高德地图 API Key:

然后你需要在显示地图前调用接口设置 API key:

import { AMapSdk } from "react-native-amap3d";
import { Platform } from "react-native";

AMapSdk.init(
  Platform.select({
    android: "c52c7169e6df23490e3114330098aaac",
    ios: "186d3464209b74effa4d8391f441f14d",
  })
);

用法

显示地图

import { MapView, MapType } from "react-native-amap3d";

<MapView
  mapType={MapType.Satellite}
  initialCameraPosition={{
    target: {
      latitude: 39.91095,
      longitude: 116.37296,
    },
    zoom: 8,
  }}
/>;

监听地图事件

import { MapView } from "react-native-amap3d";

<MapView
  onLoad={() => console.log("onLoad")}
  onPress={({ nativeEvent }) => console.log(nativeEvent)}
  onCameraIdle={({ nativeEvent }) => console.log(nativeEvent)}
/>;

添加标记

其中 icon 支持 ImageSource

同时支持 children 作为标记图标。

import { MapView, Marker } from "react-native-amap3d";

<MapView>
  <Marker
    position={{ latitude: 39.806901, longitude: 116.397972 }}
    icon={require("../images/flag.png")}
    onPress={() => alert("onPress")}
  />
  <Marker
    position={{ latitude: 39.806901, longitude: 116.297972 }}
    icon={{
      uri: "https://reactnative.dev/img/pwa/manifest-icon-512.png",
      width: 64,
      height: 64,
    }}
  />
  <Marker position={{ latitude: 39.906901, longitude: 116.397972 }}>
    <Text
      style={{
        color: "#fff",
        backgroundColor: "#009688",
        alignItems: "center",
        borderRadius: 5,
        padding: 5,
      }}
    >
      {new Date().toLocaleString()}
    </Text>
  </Marker>
</MapView>;

点聚合

Marker 数量过多(尤其是使用自定义 View 的情况下)会导致性能问题,而且显示过于密集,这时候可以用点聚合改善。

import { Cluster, MapView, Marker } from "react-native-amap3d";

const markers = Array(1000)
  .fill(0)
  .map((_, i) => ({
    position: { latitude: 39.5 + Math.random(), longitude: 116 + Math.random() },
    properties: { key: `Marker${i}` },
  }));

<MapView
  ref={(ref) => (this.mapView = ref)}
  onLoad={() => this.mapView?.moveCamera({ zoom: 8 }, 100)}
  onCameraIdle={({ nativeEvent }) => {
    this.status = nativeEvent;
    this.cluster?.update(nativeEvent);
  }}
>
  <Cluster
    ref={(ref) => (this.cluster = ref)}
    points={markers}
    renderMarker={(item) => (
      <Marker
        key={item.properties.key}
        icon={require("../images/flag.png")}
        position={item.position}
      />
    )}
  />
</MapView>;

更多示例

参考 example

常见问题

  • 尽量使用真实设备进行测试,在模拟器可能存在一些问题(常见的是 Android 模拟器因为缺少 GPU 加速而导致闪退)。
  • onLocation 没有返回定位数据通常是因为 key 不正确,或没有申请 PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION 权限

More Repositories

1

react-native-amap-geolocation

React Native geolocation module for Android + iOS
TypeScript
383
star
2

react-native-baidumap-sdk

React Native BaiduMap SDK for Android + iOS
Kotlin
329
star
3

tuner

Online tuner based on web audio api
JavaScript
311
star
4

aubiojs

aubio for javascript, the real-time audio processing library
C++
132
star
5

ky-genshin-map

超级丝滑的原神地图,数据来源:空荧酒馆。
TypeScript
130
star
6

react-native-recording

React Native audio recording module used for DSP with Android + iOS
Java
107
star
7

react-native-tuner

A tuner app written in react native, support ios and android.
JavaScript
80
star
8

flutter-android-window

A flutter plugin allows you to create native android floating window.
Kotlin
62
star
9

canvaskit-map

基于 canvaskit,高性能、丝滑的平面地图引擎。
TypeScript
56
star
10

solidity-ls

Solidity language server.
TypeScript
56
star
11

coc-solidity

Solidity language server for coc.nvim
TypeScript
48
star
12

genshin-maps

极致流畅的原神地图 app,支持 android、web、linux、windows、macos
41
star
13

pydoubanfm

Python 实现的豆瓣FM客户端
Python
37
star
14

flutter-fish-completions

fish completions for flutter
Shell
25
star
15

boxbot

百度前端技术学院2016春季班任务:听指令的小方块
JavaScript
22
star
16

gallery

在线相册展示,包括拼图布局、瀑布流、木桶布局
JavaScript
19
star
17

simple_candlestick_chart

A simple candlestick chart for flutter. Supports smooth scroll and zoom.
Dart
19
star
18

pep

Python PEP 中文翻译
13
star
19

doubanfm.sh

Bash douban.fm 客户端
Shell
12
star
20

custom_notched_shape

Flutter BottomAppBar 自定义路径 + 贝塞尔曲线实现闲鱼底部导航类似的效果
Dart
12
star
21

ife2016

百度前端技术学院 2016
HTML
7
star
22

cross_file_image

ImageProvider for XFile
Dart
7
star
23

flutter-tencent-map

flutter 腾讯地图组件(开发中)
Dart
6
star
24

canvas-tilemap

Super smooth 2d tilemap build with canvas2d.
TypeScript
6
star
25

flutter-zhihu

Dart
5
star
26

react-native-rongcloud-imlib

非官方仓库,用于 CI 以及接口文档托管,官方仓库:rongcloud / rongcloud-react-native-imlib
Java
5
star
27

flutter_image_saver

Simple and effective cross platform image saver for flutter, supported web and desktop
Dart
4
star
28

gallery-server

JavaScript
3
star
29

bilibili.sh

Bash 实现的 bilibili 播放器
Python
2
star
30

flutter-finanical-charts-v1

JavaScript
2
star
31

flutter-baidu-map

Dart
2
star
32

flutter-finanical-charts-v2

JavaScript
2
star
33

moyukik

摸鱼 kik 首页实现及优化
Dart
2
star
34

canvas-genshin-maps

超级丝滑的原神地图,基于 canvas2d,全新实现的地图手势识别及渲染,可在手机浏览器下提供接近原生地图的体验。
TypeScript
2
star
35

ethereum-contract-ui

Ethereum contract UI for contract testing without writing any code.
TypeScript
1
star
36

flutter-sound-recording

Flutter sound recording plugin for DSP purposes, now supports android.
Dart
1
star
37

flutter-antd

Dart
1
star
38

flutter_map_demo

Dart
1
star
39

maps

Kotlin
1
star
40

flutter-pay-pwd

Flutter 6 digital payment password input
Dart
1
star
41

wechat

Wechat SDK
PHP
1
star
42

flutter-launcher

应用启动器,为了在超级省电模式下打开其他应用
Dart
1
star
43

indicator-hiwifi

极路由流量监视器
Python
1
star
44

personal-radio

Cloudmusic personal radio player
JavaScript
1
star
45

pycomic

Python 实现的漫画下载工具
Python
1
star