Git Product home page Git Product logo

react-native-amap3d's Introduction

react-native-amap3d npm version build status

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

功能

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

安装

安装依赖

$ npm i react-native-amap3d

$ yarn add react-native-amap3d

项目配置

Android

$ react-native link react-native-amap3d

iOS

推荐使用 CocoaPods,需要注意 iOS 项目不要 react-native link react-native-amap3d, 不然会引入错误的依赖,导致编译失败。在 ios 目录下新建文件 Podfile

platform :ios, '8.0'

target 'Your Target' do
  pod 'yoga', path: '../node_modules/react-native/ReactCommon/yoga/'
  pod 'React', path: '../node_modules/react-native/', :subspecs => [
    'BatchedBridge',
    'DevSupport',
  ]
  pod 'react-native-amap3d', path: '../node_modules/react-native-amap3d/lib/ios/'
end

然后运行:

$ pod install

如果你不想使用 CocoaPods,手动配置请参考:手动部署

添加高德 Key

Android

  1. 获取高德 Key

  2. 编辑 Android 项目的 AndroidManifest.xml(一般在 android\app\src\main\AndroidManifest.xml),添加如下代码:

    <application>
      <meta-data
        android:name="com.amap.api.v2.apikey"
        android:value="你的高德 Key" />
    </application>

iOS

  1. 获取高德 Key

  2. AppDelegate.m 里引入 SDK 头文件 #import <AMapFoundationKit/AMapFoundationKit.h>, 并设置高德 Key [AMapServices sharedServices].apiKey = @"你的高德 Key";

用法

导入地图模块

import { MapView } from 'react-native-amap3d'

基本用法

<MapView
  coordinate={{
    latitude: 39.91095,
    longitude: 116.37296,
  }}
/>

启用定位并监听定位事件

<MapView
  locationEnabled
  onLocation={({ nativeEvent }) =>
    console.log(`${nativeEvent.latitude}, ${nativeEvent.longitude}`)}
/>

添加可拖拽的地图标记

<MapView>
  <MapView.Marker
    draggable
    title='这是一个可拖拽的标记'
    onDragEnd={({ nativeEvent }) =>
      console.log(`${nativeEvent.latitude}, ${nativeEvent.longitude}`)}
    coordinate={{
      latitude: 39.91095,
      longitude: 116.37296,
    }}
  />
</MapView>

自定义标记图片及信息窗体

const coordinate = {
  latitude: 39.706901,
  longitude: 116.397972,
}

<MapView.Marker image='flag' coordinate={coordinate}>
  <View style={styles.customInfoWindow}>
    <Text>自定义信息窗体</Text>
  </View>
</MapView.Marker>

更多示例

examples

Android

$ yarn
$ yarn run-android

iOS

$ yarn
$ cd ios && pod install && cd ..
$ yarn run-ios

接口

请参考注释文档:

关于编译问题

鉴于编译问题重复提得太多,且没有什么讨论价值,有必要单独做一些说明。

为了方便排除问题,这个项目是有在持续集成里做编译测试的。 其中在 master 分支做 example 的编译测试,在 release 分支做新项目的编译测试。 在提编译问题之前,请先检查最新的编译测试。当然,如果你熟悉编译过程, 并且发现这个项目的配置确实存在问题,欢迎提出、讨论。

react-native-amap3d's People

Contributors

qiuxiang avatar yiiu avatar xhuang3 avatar

Watchers

James Cloos avatar Aries avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.