react-native-open-maps icon indicating copy to clipboard operation
react-native-open-maps copied to clipboard

Add bicycling option for travelType

Open 0x3dev opened this issue 2 years ago • 1 comments

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

0x3dev avatar Jun 01 '23 08:06 0x3dev

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

  • Google Maps: pass bicycling as travelmode
  • Apple Maps: pass c as dirflg

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 = {

huygo88 avatar Aug 01 '24 18:08 huygo88