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 )
2
7
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 )
6
8
7
9
---
10
+ </div >
8
11
9
12
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 设备无法识别地图应用的问题,如华为手机等。
11
22
12
23
<details >
13
24
<summary ><strong >Full list of supported apps</strong ></summary >
14
25
26
+ - Gaode Maps – ` amap `
27
+ - Baidu Maps – ` baidumap `
28
+ - Tencent Maps – ` qqmap `
15
29
- Apple Maps – ` apple-maps `
16
30
- Google Maps – ` google-maps `
17
31
- Citymapper – ` citymapper `
@@ -39,22 +53,31 @@ on their device. The app supports Apple Maps, Google Maps, Citymapper, Uber, and
39
53
</details >
40
54
41
55
<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 " />
44
60
</p >
45
61
46
62
## Installation
47
63
48
64
### 1. Install the package
49
65
50
66
``` 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
52
70
```
53
71
54
72
### 2. Post-install steps
55
73
56
74
Based on the platforms your app supports, you also need to:
57
75
76
+ ** 注意:**
77
+ - 切记更新 iOS 和 Android 配置,否则将无法调起地图应用;
78
+ - 仅在中国使用的话,可以剔除大部分国外地图应用,保留 ` iosamap ` 、` androidmap ` 、` baidumap ` 、` qqmap ` ;
79
+ - 繁体中文地区,支持显示繁体,但未经过实地测试,欢迎参与测试。
80
+
58
81
<details id =" iOSPostInstall " >
59
82
<summary ><strong >iOS – Update Info.plist</strong ></summary >
60
83
@@ -65,6 +88,10 @@ Just add this in your `Info.plist` depending on which apps you'd like to support
65
88
``` xml
66
89
<key >LSApplicationQueriesSchemes</key >
67
90
<array >
91
+ <string >iosamap</string >
92
+ <string >androidamap</string >
93
+ <string >baidumap</string >
94
+ <string >qqmap</string >
68
95
<string >comgooglemaps</string >
69
96
<string >citymapper</string >
70
97
<string >uber</string >
@@ -114,6 +141,19 @@ You can do so by coping the `<queries>` statement below, and pasting it in the t
114
141
<action android : name =" android.intent.action.VIEW" />
115
142
<data android : scheme =" geo" />
116
143
</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 >
117
157
<intent >
118
158
<action android : name =" android.intent.action.VIEW" />
119
159
<data android : scheme =" google.navigation" />
@@ -229,7 +269,7 @@ More info [here](https://stackoverflow.com/a/67383641/1129689).
229
269
## Simple example
230
270
231
271
``` js
232
- import {showLocation } from ' react-native-map-link' ;
272
+ import { showLocation } from ' react-native-map-link-x ' ;
233
273
234
274
showLocation ({
235
275
latitude: 38.8976763 ,
@@ -238,12 +278,66 @@ showLocation({
238
278
});
239
279
```
240
280
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
+
241
335
## Full usage
242
336
243
337
Using the ` showLocation` function will shown an action sheet on iOS and an alert on Android, without any custom styling:
244
338
245
339
` ` ` js
246
- import {showLocation } from ' react-native-map-link' ;
340
+ import { showLocation } from ' react-native-map-link-x ' ;
247
341
248
342
showLocation ({
249
343
latitude: 38.8976763 ,
@@ -257,7 +351,7 @@ showLocation({
257
351
dialogTitle: ' This is the dialog Title' , // optional (default: 'Open in Maps')
258
352
dialogMessage: ' This is the amazing dialog Message' , // optional (default: 'What app would you like to use?')
259
353
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)
261
355
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.
262
356
appTitles: {' google-maps' : ' My custom Google Maps title' }, // optionally you can override default app titles
263
357
app: ' uber' , // optionally specify specific app to use
@@ -268,7 +362,7 @@ showLocation({
268
362
Alternatively you can specify the ` address` field and leave the latitude and longitude properties as empty strings
269
363
270
364
` ` ` js
271
- import {showLocation } from ' react-native-map-link' ;
365
+ import { showLocation } from ' react-native-map-link-x ' ;
272
366
273
367
showLocation ({
274
368
address: ' 1600 Pennsylvania Avenue NW, Washington, DC 20500' , // Required if replacing latitude and longitude
@@ -297,7 +391,7 @@ type GetAppResult = {
297
391
` ` `
298
392
299
393
` ` ` tsx
300
- import {getApps , GetAppResult } from ' react-native-map-link' ;
394
+ import { getApps , GetAppResult } from ' react-native-map-link-x ' ;
301
395
302
396
const Demo = () => {
303
397
const [availableApps , setAvailableApps ] = useState< GetAppResult[]> ([]);
0 commit comments