npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-map-link-x

v3.6.2

Published

Open the map app of the user's choice with a specific location (Fork from react-native-map-link). Support chinese map apps (Gaode, Baidu and Tencent).

Downloads

35

Readme

react-native-map-link-x

GitHub release npm GitHub license


An easy way to open a location in a map app of the user's choice, based on the apps they have installed on their device. The app supports Apple Maps, Google Maps, Citymapper, Uber and a dozen other apps.

This is fork from 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.


根据用户设备中已安装的地图应用,提供一种便捷方式,打开用户所选的定位导航。支持苹果地图、谷歌地图、优步,以及其他国外主流地图应用。

本库 Fork 自 react-native-map-link,在原库的基础上,添加对高德地图百度地图腾讯地图的支持。另外,解决部分 Android 设备无法识别地图应用的问题,如华为手机等。

  • Gaode Maps – amap
  • Baidu Maps – baidumap
  • Tencent Maps – qqmap
  • Apple Maps – apple-maps
  • Google Maps – google-maps
  • Citymapper – citymapper
  • Uber – uber
  • Lyft – lyft
  • The Transit App – transit
  • TruckMap – truckmap
  • Waze – waze
  • Yandex.Navi – yandex
  • Moovit – moovit
  • Yandex Taxi – yandex-taxi
  • Yandex Maps – yandex-maps
  • Kakao Map – kakaomap
  • TMAP - tmap
  • Mapy.cz – mapycz
  • Maps.me – maps-me
  • OsmAnd - osmand
  • Gett - gett
  • Naver Map - navermap
  • 2GIS - dgis
  • Liftago - liftago
  • Petal Maps - petalmaps (Android only)
  • Sygic - sygic

Installation

1. Install the package

npm i -S react-native-map-link-x
# or
yarn add react-native-map-link-x

2. Post-install steps

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

注意:

  • 切记更新 iOS 和 Android 配置,否则将无法调起地图应用;
  • 仅在中国使用的话,可以剔除大部分国外地图应用,保留 iosamapandroidmapbaidumapqqmap
  • 繁体中文地区,支持显示繁体,但未经过实地测试,欢迎参与测试。

To allow your app to detect if any of the directions apps are installed, an extra step is required on iOS. Your app needs to provide the LSApplicationQueriesSchemes key inside ios/{my-project}/Info.plist to specify the URL schemes with which the app can interact.

Just add this in your Info.plist depending on which apps you'd like to support. Omitting these might mean that the library can't detect some of the maps apps installed by the user.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>iosamap</string>
    <string>androidamap</string>
    <string>baidumap</string>
    <string>qqmap</string>
    <string>comgooglemaps</string>
    <string>citymapper</string>
    <string>uber</string>
    <string>lyft</string>
    <string>transit</string>
    <string>truckmap</string>
    <string>waze</string>
    <string>yandexnavi</string>
    <string>moovit</string>
    <string>yandextaxi</string>
    <string>yandexmaps</string>
    <string>kakaomap</string>
    <string>tmap</string>
    <string>szn-mapy</string>
    <string>mapsme</string>
    <string>osmandmaps</string>
    <string>gett</string>
    <string>nmap</string>
    <string>dgis</string>
    <string>lftgpas</string>
    <string>sygic</string>
</array>

Using Expo? Read the instructions to make it work on iOS.

When switching to Android 11/Android SDK 30 (i.e. using Expo SDK 41), this library doesn't work out of the box anymore. The reason is the new Package Visibilty security feature. We'll have to update our AndroidManifest.xml to explicitly allow querying for other apps.

You can do so by coping the <queries> statement below, and pasting it in the top level of your AndroidManifest (i.e. within the <manifest> ... </manifest>).

<queries>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="http"/>
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https"/>
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="geo" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="androidamap"/>
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="baidumap"/>
    <data android:host="map"/>
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="qqmap"/>
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="google.navigation" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="applemaps" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="citymapper" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="uber" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="lyft" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="transit" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="truckmap" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="waze" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="yandexnavi" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="moovit" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="yandexmaps://maps.yandex." />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="yandextaxi" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="kakaomap" />
  </intent>
    <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="tmap" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="mapycz" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="mapsme" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="osmand.geo" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="gett" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="nmap" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="dgis" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="lftgpas" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="petalmaps" />
  </intent>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="com.sygic.aura" />
  </intent>
</queries>

If you're running into a 'unexpected element <queries> found in <manifest>' error, make sure you have an updated version of Gradle in your android/build.gradle file:

classpath("com.android.tools.build:gradle:3.5.4")

More info here.

Read the instructions here

Simple example

import { showLocation } from 'react-native-map-link-x';

showLocation({
  latitude: 38.8976763,
  longitude: -77.0387185,
  title: 'Your destination',
});

Chinese example

使用默认组件显示地图应用列表:

import { showLocation } from 'react-native-map-link-x';

// 弹出默认地图应用列表
showLocation({
  latitude: 24.436048,
  longitude: 118.088061,
  title: '世贸海峡大厦',
  address: '厦门市思明区演武西路180-188号',
  dialogTitle: '在地图中打开',
  dialogMessage: '请选择您想要打开的地图',
  cancelText: '取消',
  appsWhiteList: ['apple-maps', 'amap', 'baidumap', 'qqmap'],
});

使用第三方 ActionSheet 组件显示地图应用列表:

import { getApps } from 'react-native-map-link-x';
// 引入第三方 ActionSheet 组件
import { useActionSheet } from '@expo/react-native-action-sheet';

...

const { showActionSheetWithOptions } = useActionSheet();

// 获取可用的地图应用列表
const apps = await getApps({
  latitude: 24.436048,
  longitude: 118.088061,
  title: '世贸海峡大厦',
  address: '厦门市思明区演武西路180-188号',
});

// 通过第三方 ActionSheet 组件显示地图应用列表
showActionSheetWithOptions({
  options: apps.map((app) => app.name).push('取消'),
}, {
  onPress: (index) => {
    const app = apps[index];
    app?.open();
  }
});

Full usage

Using the showLocation function will shown an action sheet on iOS and an alert on Android, without any custom styling:

import { showLocation } from 'react-native-map-link-x';

showLocation({
  latitude: 38.8976763,
  longitude: -77.0387185,
  sourceLatitude: -8.0870631, // optionally specify starting location for directions
  sourceLongitude: -34.8941619, // required if sourceLatitude is specified
  title: 'The White House', // optional 
  googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
  googlePlaceId: 'ChIJGVtI4by3t4kRr51d_Qm_x58', // optionally specify the google-place-id
  alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)
  dialogTitle: 'This is the dialog Title', // optional (default: 'Open in Maps')
  dialogMessage: 'This is the amazing dialog Message', // optional (default: 'What app would you like to use?')
  cancelText: 'This is the cancel button text', // optional (default: 'Cancel')
  appsWhiteList: ['amap', 'baidumap', 'qqmap'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
  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.
  appTitles: {'google-maps': 'My custom Google Maps title'}, // optionally you can override default app titles
  app: 'uber', // optionally specify specific app to use
  directionsMode: 'walk', // optional, accepted values are 'car', 'walk', 'public-transport' or 'bike'
});

Alternatively you can specify the address field and leave the latitude and longitude properties as empty strings

import { showLocation } from 'react-native-map-link-x';

showLocation({
  address: '1600 Pennsylvania Avenue NW, Washington, DC 20500', // Required if replacing latitude and longitude
  app: 'comgooglemaps',  // optionally specify specific app to use
});

Notes:

  • The sourceLatitude / sourceLongitude options only work if you specify both. Currently supports all apps except Waze.
  • directionsMode works on google-maps, apple-maps and sygic (on apple-maps, bike mode will not work, while on sygic, only walk and car will work). Without setting it, the app will decide based on its own settings.
  • If you set directionsMode but do not set sourceLatitude and sourceLongitude, google-maps and apple-maps will still enter directions mode, and use the current location as starting point.
  • If you want to query an address instead of passing the latitude and longitude fields, you can do this by leaving those fields off and provide a full address to be queried with the address field. Just be aware that not all applications support this.

Or

Using the getApps function will return an array (GetAppResult[]) with the apps available on the smartphone:

type GetAppResult = {
  id: string;
  name: string;
  icon: NodeRequire;
  open: () => Promise<void>;
};
import { getApps, GetAppResult } from 'react-native-map-link-x';

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

  useEffect(() => {
    (async () => {
      const result = await getApps({
        latitude: 38.8976763,
        longitude: -77.0387185,
        address: '1600 Pennsylvania Avenue NW, Washington, DC 20500', // optional 
        title: 'The White House', // optional
        googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
        alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)
        appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
      });
      setAvailableApps(result);
    })();
  }, []);

  return (
    <React.Fragment>
      {availableApps.map(({icon, name, id, open}) => (
        <Pressable key={id} onPress={open}>
          <Image source={icon} />
          <Text>{name}</Text>
        </Pressable>
      ))}
    </React.Fragment>
  );
};

More information