brh55 / react-native-open-maps

🗺 A simple react-native library to perform cross-platform map actions (Google, Apple, or Yandex Maps)
MIT License
359 stars 47 forks source link

Add bicycling option for travelType #77

Open 0x3dev opened 1 year ago

0x3dev commented 1 year ago

Hello. For Google Maps at least, there is a bicycling option. Can we have it in this library too? Thanks!

https://developers.google.com/maps/documentation/javascript/directions#TravelModes

huygo88 commented 2 months ago

For those looking to support bicycling, you can patch the package with the following:

Use patch-package:

patches/react-native-open-maps+0.4.3.patch

diff --git a/node_modules/react-native-open-maps/index.d.ts b/node_modules/react-native-open-maps/index.d.ts
index c0a8691..b365e0f 100644
--- a/node_modules/react-native-open-maps/index.d.ts
+++ b/node_modules/react-native-open-maps/index.d.ts
@@ -13,7 +13,7 @@ declare module 'react-native-open-maps' {
     /** Google Maps: Will use a Place ID for the query for Google Maps */
     queryPlaceId?: string
     /** Use this parameter in conjunction with start and end to determine transportation type. Default is drive "drive". */
-    travelType?: 'drive' | 'walk' | 'public_transport'
+    travelType?: 'drive' | 'walk' | 'public_transport' | 'bike'
     /** The start location that can be interpreted as a geolocation, omit if you want to use current location / "My Location". See Apple and Google docs for more details on how to define geolocations. "New York City, New York, NY" */
     start?: string
     /** The end location that can be interpreted as a geolocation. See Apple and Google docs for more details on how to define geolocations. Example: "SOHO, New York, NY" */
diff --git a/node_modules/react-native-open-maps/index.js b/node_modules/react-native-open-maps/index.js
index 2ff95fa..ff26067 100644
--- a/node_modules/react-native-open-maps/index.js
+++ b/node_modules/react-native-open-maps/index.js
@@ -20,7 +20,7 @@ export const validateEnum = (enums = []) => (type) => {
    return true;
 }

-export const validateTravelType = validateEnum(['drive', 'walk', 'public_transport']);
+export const validateTravelType = validateEnum(['drive', 'walk', 'public_transport', 'bike']);
 export const validateMapType = validateEnum(['standard', 'satellite', 'hybrid', 'transit']);

 // cleanObject :: {} -> {}
@@ -39,7 +39,8 @@ export const createAppleParams = options => {
    const travelTypeMap = {
        drive: 'd',
        walk: 'w',
-       public_transport: 'r'
+       public_transport: 'r',
+       bike: 'c'
    };

    const baseTypeMap = {
@@ -78,7 +79,8 @@ export const createGoogleParams = options => {
    const travelTypeMap = {
        drive: 'driving',
        walk: 'walking',
-       public_transport: 'transit'
+       public_transport: 'transit',
+       bike: 'bicycling'
    };

    const baseTypeMap = {
@@ -121,7 +123,8 @@ export const createYandexParams = options => {
    const travelTypeMap = {
        drive: 'auto',
        walk: 'pd',
-       public_transport: 'mt'
+       public_transport: 'mt',
+           bike: 'auto'
    };

    const baseTypeMap = {