Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuxiang committed Jun 9, 2020
1 parent 0741b87 commit 31468e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 85 deletions.
82 changes: 4 additions & 78 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,95 +9,21 @@

## 安装

```
yarn add react-native-amap-geolocation
```

或使用 npm:

```
npm i react-native-amap-geolocation
```

## 自动配置(推荐)

```
react-native link react-native-amap-geolocation
```

## 手动配置

一般情况下 react-native link 即可完成配置,如果因特殊原因无法使用 react-native link
或 link 失败,则可参照以下步骤检查并进行手动配置。

### Android

1. 编辑 `android/settings.gradle`,设置项目路径:

```diff
include ':react-native-amap-geolocation'
+ project(':react-native-amap-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-amap-geolocation/lib/android')
```

2. 编辑 `android/app/build.gradle`,新增依赖:

```diff
dependencies {
+ implementation project(':react-native-amap-geolocation')
}
```

3. 编辑 `MainApplication.java`

```diff
+ import cn.qiuxiang.react.geolocation.AMapGeolocationPackage;

public class MainApplication extends Application implements ReactApplication {
@Override
protected List<ReactPackage> getPackages() {
return Arrays.asList(
new MainReactPackage(),
+ new AMapGeolocationPackage()
);
}
}
```

### iOS

1. Project navigator ➜ 右击 Libraries ➜ 选择 `Add Files to "XXXX"...`

2. 选择并添加 `node_modules/react-native-amap-geolocation/lib/ios/AMapGeolocation.xcodeproj`
(或从文件浏览器里将该文件拖拽到 Libraries)

3. Build Phases ➜ Link Binary With Libraries 中选择并添加 libAMapGeolocation.a

## iOS 项目的额外配置

对于 iOS 项目无论如何还要手动下载 SDK 并进行一些必要的配置,也可以参考官方文档:
[手动部署](https://lbs.amap.com/api/ios-location-sdk/guide/create-project/manual-configuration)

### 下载 iOS SDK

1. 从官方网站下载 [基础 SDK(含 IDFA)](https://a.amap.com/lbs/static/zip/AMap_iOS_Foundation_Lib_V1.4.3.zip)
[定位 SDK](https://a.amap.com/lbs/static/zip/AMap_iOS_Loc_Lib_V2.6.2.zip) 并解压到 `ios/`
(注意 `*.framework` 文件必须放到 `ios/` 目录,一定要放到其他目录请自行设置 AMapGeolocation.xcodeproj 的 Search Path)。

2. 将解压得到的 `AMapFoundationKit.framework``AMapLocationKit.framework` 以及
`ExternalAccessory.framework` 添加到 Build Phases ➜ Link Binary With Libraries。

### 添加权限申请

在 iOS 项目的 Info.plist 添加定位权限申请。

## 基本用法

```javascript
import { PermissionsAndroid } from "react-native";
import { init, Geolocation } from "react-native-amap-geolocation";

// 对于 Android 需要自行根据需要申请权限
await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION);
await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
]);

// 使用自己申请的高德 App Key 进行初始化
await init({
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
],
"main": "lib/js",
"scripts": {
"dev": "tsc -w",
"build": "tsc",
"build-docs": "typedoc --out docs/api --excludeNotExported --module commonjs --mode file src",
"start": "node node_modules/react-native/local-cli/cli.js start",
"dev": "npx typescript -w",
"build": "npx typescript",
"build-docs": "npx typedoc --out docs/api --excludeNotExported --module commonjs --mode file src",
"start": "npx react-native start",
"reload": "adb reverse tcp:8081 tcp:8081 && adb shell input text rr",
"run-android": "node node_modules/react-native/local-cli/cli.js run-android",
"release-android": "node node_modules/react-native/local-cli/cli.js run-android --variant=release",
"run-ios": "node node_modules/react-native/local-cli/cli.js run-ios"
"run-android": "npx react-native run-android",
"release-android": "npx react-native run-android --variant=release",
"run-ios": "npx react-native run-ios"
},
"devDependencies": {
"@babel/core": "^7.6.2",
Expand Down

0 comments on commit 31468e5

Please sign in to comment.