Skip to content

Commit 385f743

Browse files
committed
add Gaode, Baidu and Tencent; resolves the issue where some devices are unable to recognize map apps
1 parent 58466c5 commit 385f743

38 files changed

+13627
-9978
lines changed

.github/workflows/nodejs.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2+
# For more information see: https://docs.github.com/zh/actions/publishing-packages/publishing-nodejs-packages
3+
name: npm-publish
4+
on:
5+
push:
6+
branches:
7+
- master # Change this to your default branch
8+
jobs:
9+
npm-publish:
10+
name: npm-publish
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 20
17+
registry-url: 'https://registry.npmjs.org/'
18+
cache: yarn
19+
- run: yarn install
20+
- run: yarn run build
21+
- run: npm publish
22+
env: # More info about the environment variables in the README
23+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} # You need to set this in your repo settings
24+

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ example/yarn.lock
1010

1111
# ts outDir
1212
lib/
13+
14+
.yarn/install-state.gz
15+
.yarnrc.yml

README.md

+107-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1-
![React Native Map Link](https://lowcdn.com/2x/8f2/3ab63c0fe3f9-00fb302c20/banner.svg)
1+
# react-native-map-link-x
2+
3+
<div style="display: none">
4+
[![GitHub release](https://img.shields.io/npm/v/react-native-map-link-x.svg)](https://www.npmjs.com/package/react-native-map-link-x)
5+
[![npm](https://img.shields.io/npm/dm/react-native-map-link-x.svg)](https://www.npmjs.com/package/react-native-map-link-x)
6+
[![GitHub license](https://img.shields.io/github/license/flexible-agency/react-native-map-link-x.svg)](https://github.com/flexible-agency/react-native-map-link-x/blob/master/LICENSE)
27

3-
[![GitHub release](https://img.shields.io/npm/v/react-native-map-link.svg)](https://www.npmjs.com/package/react-native-map-link)
4-
[![npm](https://img.shields.io/npm/dm/react-native-map-link.svg)](https://www.npmjs.com/package/react-native-map-link)
5-
[![GitHub license](https://img.shields.io/github/license/flexible-agency/react-native-map-link.svg)](https://github.com/flexible-agency/react-native-map-link/blob/master/LICENSE)
68

79
---
10+
</div>
811

912
An easy way to open a location in a map app of the user's choice, based on the apps they have installed
10-
on their device. The app supports Apple Maps, Google Maps, Citymapper, Uber, and a dozen other apps.
13+
on their device. The app supports Apple Maps, Google Maps, Citymapper, Uber and a dozen other apps.
14+
15+
This is fork from [react-native-map-link](https://github.com/christopherdro/react-native-map-link). Based on the original library, it adds support for `Gaode Maps`, `Baidu Maps`, and `Tencent Maps`. Additionally, it resolves the issue where some devices, are unable to recognize map apps, such as Huawei.
16+
17+
---
18+
19+
根据用户设备中已安装的地图应用,提供一种便捷方式,打开用户所选的定位导航。支持苹果地图、谷歌地图、优步,以及其他国外主流地图应用。
20+
21+
本库 Fork 自 [react-native-map-link](https://github.com/christopherdro/react-native-map-link),在原库的基础上,添加对`高德地图``百度地图``腾讯地图`的支持。另外,解决部分 Android 设备无法识别地图应用的问题,如华为手机等。
1122

1223
<details>
1324
<summary><strong>Full list of supported apps</strong></summary>
1425

26+
- Gaode Maps – `amap`
27+
- Baidu Maps – `baidumap`
28+
- Tencent Maps – `qqmap`
1529
- Apple Maps – `apple-maps`
1630
- Google Maps – `google-maps`
1731
- Citymapper – `citymapper`
@@ -39,22 +53,31 @@ on their device. The app supports Apple Maps, Google Maps, Citymapper, Uber, and
3953
</details>
4054

4155
<br /><p align="center">
42-
<img src="./docs/example.png" alt="Example screenshot" width="320" />
43-
56+
<img src="./docs/example.png" alt="Example screenshot" width="240" />
57+
<img src="./docs/example-zh0.png" alt="Example screenshot" width="240" />
58+
<img src="./docs/example-zh1.png" alt="Example screenshot" width="240" />
59+
<img src="./docs/example-zh2.png" alt="Example screenshot" width="240" />
4460
</p>
4561

4662
## Installation
4763

4864
### 1. Install the package
4965

5066
```shell
51-
npm i -S react-native-map-link # or yarn add react-native-map-link
67+
npm i -S react-native-map-link-x
68+
# or
69+
yarn add react-native-map-link-x
5270
```
5371

5472
### 2. Post-install steps
5573

5674
Based on the platforms your app supports, you also need to:
5775

76+
**注意:**
77+
- 切记更新 iOS 和 Android 配置,否则将无法调起地图应用;
78+
- 仅在中国使用的话,可以剔除大部分国外地图应用,保留 `iosamap``androidmap``baidumap``qqmap`
79+
- 繁体中文地区,支持显示繁体,但未经过实地测试,欢迎参与测试。
80+
5881
<details id="iOSPostInstall">
5982
<summary><strong>iOS – Update Info.plist</strong></summary>
6083

@@ -65,6 +88,10 @@ Just add this in your `Info.plist` depending on which apps you'd like to support
6588
```xml
6689
<key>LSApplicationQueriesSchemes</key>
6790
<array>
91+
<string>iosamap</string>
92+
<string>androidamap</string>
93+
<string>baidumap</string>
94+
<string>qqmap</string>
6895
<string>comgooglemaps</string>
6996
<string>citymapper</string>
7097
<string>uber</string>
@@ -114,6 +141,19 @@ You can do so by coping the `<queries>` statement below, and pasting it in the t
114141
<action android:name="android.intent.action.VIEW" />
115142
<data android:scheme="geo" />
116143
</intent>
144+
<intent>
145+
<action android:name="android.intent.action.VIEW" />
146+
<data android:scheme="androidamap"/>
147+
</intent>
148+
<intent>
149+
<action android:name="android.intent.action.VIEW" />
150+
<data android:scheme="baidumap"/>
151+
<data android:host="map"/>
152+
</intent>
153+
<intent>
154+
<action android:name="android.intent.action.VIEW" />
155+
<data android:scheme="qqmap"/>
156+
</intent>
117157
<intent>
118158
<action android:name="android.intent.action.VIEW" />
119159
<data android:scheme="google.navigation" />
@@ -229,7 +269,7 @@ More info [here](https://stackoverflow.com/a/67383641/1129689).
229269
## Simple example
230270

231271
```js
232-
import {showLocation} from 'react-native-map-link';
272+
import { showLocation } from 'react-native-map-link-x';
233273

234274
showLocation({
235275
latitude: 38.8976763,
@@ -238,12 +278,66 @@ showLocation({
238278
});
239279
```
240280

281+
## Chinese example
282+
283+
使用默认组件显示地图应用列表:
284+
285+
```js
286+
import { showLocation } from 'react-native-map-link-x';
287+
288+
// 弹出默认地图应用列表
289+
showLocation({
290+
latitude: 24.436048,
291+
longitude: 118.088061,
292+
title: '世贸海峡大厦',
293+
address: '厦门市思明区演武西路180-188号',
294+
dialogTitle: '在地图中打开',
295+
dialogMessage: '请选择您想要打开的地图',
296+
cancelText: '取消',
297+
appsWhiteList: ['apple-maps', 'amap', 'baidumap', 'qqmap'],
298+
});
299+
```
300+
使用第三方 ActionSheet 组件显示地图应用列表:
301+
302+
```js
303+
import { getApps } from 'react-native-map-link-x';
304+
// 引入第三方 ActionSheet 组件
305+
import { useActionSheet } from '@expo/react-native-action-sheet';
306+
307+
...
308+
309+
const { showActionSheetWithOptions } = useActionSheet();
310+
311+
// 获取可用的地图应用列表
312+
const apps = await getApps({
313+
latitude: 24.436048,
314+
longitude: 118.088061,
315+
title: '世贸海峡大厦',
316+
address: '厦门市思明区演武西路180-188号',
317+
dialogTitle: '在地图中打开',
318+
dialogMessage: '请选择您想要打开的地图',
319+
cancelText: '取消',
320+
appsWhiteList: ['apple-maps', 'amap', 'baidumap', 'qqmap'],
321+
});
322+
323+
// 通过第三方 ActionSheet 组件显示地图应用列表
324+
showActionSheetWithOptions({
325+
options: apps.map((app) => app.name).push('取消'),
326+
}, {
327+
onPress: (index) => {
328+
const app = apps[index];
329+
app?.open();
330+
}
331+
});
332+
```
333+
334+
241335
## Full usage
242336
243337
Using the `showLocation` function will shown an action sheet on iOS and an alert on Android, without any custom styling:
244338
245339
```js
246-
import {showLocation} from 'react-native-map-link';
340+
import { showLocation } from 'react-native-map-link-x';
247341

248342
showLocation({
249343
latitude: 38.8976763,
@@ -257,7 +351,7 @@ showLocation({
257351
dialogTitle: 'This is the dialog Title', // optional (default: 'Open in Maps')
258352
dialogMessage: 'This is the amazing dialog Message', // optional (default: 'What app would you like to use?')
259353
cancelText: 'This is the cancel button text', // optional (default: 'Cancel')
260-
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
354+
appsWhiteList: ['amap', 'baidumap', 'qqmap'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
261355
naverCallerName: 'com.example.myapp', // to link into Naver Map You should provide your appname which is the bundle ID in iOS and applicationId in android.
262356
appTitles: {'google-maps': 'My custom Google Maps title'}, // optionally you can override default app titles
263357
app: 'uber', // optionally specify specific app to use
@@ -268,7 +362,7 @@ showLocation({
268362
Alternatively you can specify the `address` field and leave the latitude and longitude properties as empty strings
269363
270364
```js
271-
import {showLocation} from 'react-native-map-link';
365+
import { showLocation } from 'react-native-map-link-x';
272366

273367
showLocation({
274368
address: '1600 Pennsylvania Avenue NW, Washington, DC 20500', // Required if replacing latitude and longitude
@@ -297,7 +391,7 @@ type GetAppResult = {
297391
```
298392
299393
```tsx
300-
import {getApps, GetAppResult} from 'react-native-map-link';
394+
import { getApps, GetAppResult } from 'react-native-map-link-x';
301395

302396
const Demo = () => {
303397
const [availableApps, setAvailableApps] = useState<GetAppResult[]>([]);

android/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

android/.gradle/config.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Fri Sep 13 09:41:02 CST 2024
2+
java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home

android/build.gradle

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apply plugin: 'com.android.library'
2+
3+
def safeExtGet(prop, fallback) {
4+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
5+
}
6+
7+
android {
8+
compileSdkVersion safeExtGet('compileSdkVersion', 28)
9+
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
10+
11+
defaultConfig {
12+
minSdkVersion safeExtGet('minSdkVersion', 16)
13+
targetSdkVersion safeExtGet('targetSdkVersion', 22)
14+
versionCode 1
15+
versionName "1.0"
16+
}
17+
18+
lintOptions {
19+
abortOnError false
20+
}
21+
}
22+
23+
repositories {
24+
maven {
25+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
26+
// Matches the RN Hello World template
27+
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L21
28+
url "$projectDir/../node_modules/react-native/android"
29+
}
30+
mavenCentral()
31+
mavenLocal()
32+
google()
33+
jcenter()
34+
35+
}
36+
37+
dependencies {
38+
implementation 'com.facebook.react:react-native:+'
39+
implementation 'androidx.appcompat:appcompat:1.2.0'
40+
implementation 'com.google.android.material:material:1.2.1'
41+
}

android/local.properties

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## This file must *NOT* be checked into Version Control Systems,
2+
# as it contains information specific to your local configuration.
3+
#
4+
# Location of the SDK. This is only used by Gradle.
5+
# For customization when using a Version Control System, please read the
6+
# header note.
7+
#Fri Sep 13 09:41:02 CST 2024
8+
sdk.dir=/Users/atypiape/Library/Android/sdk

android/src/main/AndroidManifest.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.svame.rn.maplink">
4+
5+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.svame.rn.maplink;
2+
3+
import android.content.pm.PackageManager;
4+
import android.text.TextUtils;
5+
6+
import com.facebook.react.bridge.Arguments;
7+
import com.facebook.react.bridge.Promise;
8+
import com.facebook.react.bridge.ReactApplicationContext;
9+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
10+
import com.facebook.react.bridge.ReactMethod;
11+
12+
public class RNMapLink extends ReactContextBaseJavaModule {
13+
private final ReactApplicationContext reactContext;
14+
15+
public RNMapLink(ReactApplicationContext reactContext) {
16+
super(reactContext);
17+
this.reactContext = reactContext;
18+
}
19+
20+
@Override
21+
public String getName() {
22+
return "RNMapLink";
23+
}
24+
25+
@ReactMethod
26+
public void isApkInstalled(String packageName, Promise promise) {
27+
if (TextUtils.isEmpty(packageName)) {
28+
promise.resolve(false);
29+
return;
30+
}
31+
32+
try {
33+
reactContext.getPackageManager().getPackageInfo(packageName, 0);
34+
promise.resolve(true);
35+
} catch (PackageManager.NameNotFoundException e) {
36+
promise.resolve(false);
37+
}
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.svame.rn.maplink;
2+
import com.facebook.react.ReactPackage;
3+
import com.facebook.react.bridge.NativeModule;
4+
import com.facebook.react.bridge.ReactApplicationContext;
5+
import com.facebook.react.uimanager.ViewManager;
6+
7+
import java.util.ArrayList;
8+
import java.util.Collections;
9+
import java.util.List;
10+
11+
public class RNMapLinkPackage implements ReactPackage {
12+
@Override
13+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
14+
List<NativeModule> modules = new ArrayList<>();
15+
16+
modules.add(new RNMapLink(reactContext));
17+
18+
return modules;
19+
}
20+
21+
@Override
22+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
23+
return Collections.emptyList();
24+
}
25+
}

docs/example-zh0.png

14.1 KB
Loading

docs/example-zh1.png

20.8 KB
Loading

docs/example-zh2.png

8.73 KB
Loading

docs/example.png

-336 KB
Loading

0 commit comments

Comments
 (0)