diff --git a/README.md b/README.md index 6933cfd..06ab086 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ on their device. The app supports Apple Maps, Google Maps, Citymapper, Uber, and - Liftago - `liftago` - Petal Maps - `petalmaps` (Android only) - Sygic - `sygic` +- What Three Words - `w3w` @@ -85,6 +86,7 @@ Just add this in your `Info.plist` depending on which apps you'd like to support dgis lftgpas sygic + w3w ``` @@ -205,6 +207,10 @@ You can do so by coping the `` statement below, and pasting it in the t + + + + ``` @@ -249,7 +255,7 @@ showLocation({ 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 + 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) @@ -265,7 +271,7 @@ showLocation({ }); ``` -Alternatively you can specify the `address` field and leave the latitude and longitude properties as empty strings +Alternatively you can specify the `address` field and leave the latitude and longitude properties as empty strings ```js import {showLocation} from 'react-native-map-link'; @@ -276,6 +282,19 @@ showLocation({ }); ``` +When using the whatThreeWords app, the 3 words should be passed into the `words` field along with the `latitude` and `longitude` properties. + +```js +import {showLocation} from 'react-native-map-link'; + +showLocation({ + latitude: 38.8976763, + longitude: -77.0387185, + words: 'rope.noses.canny', // Required if using w3w provider + app: 'w3w', // optionally specify specific app to use +}); +``` + Notes: - The `sourceLatitude` / `sourceLongitude` options only work if you specify both. Currently supports all apps except Waze. @@ -307,7 +326,7 @@ const Demo = () => { const result = await getApps({ latitude: 38.8976763, longitude: -77.0387185, - address: '1600 Pennsylvania Avenue NW, Washington, DC 20500', // optional + 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) diff --git a/src/constants.ts b/src/constants.ts index 27439f4..ddad359 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -34,6 +34,7 @@ export const generatePrefixes = ({ liftago: 'lftgpas://', petalmaps: 'petalmaps://', sygic: 'com.sygic.aura://', + w3w: 'w3w://', }; }; @@ -70,6 +71,7 @@ export const generateTitles = ( liftago: 'Liftago', petalmaps: 'Petal Maps', sygic: 'Sygic', + w3w: 'What3Words', ...(titles || {}), }; }; @@ -98,6 +100,7 @@ export const icons: Record = { liftago: require('./images/liftago.png'), petalmaps: require('./images/petalmaps.png'), sygic: require('./images/sygic.png'), + w3w: require('./images/w3w.png'), }; export const appKeys: string[] = Object.keys(icons); diff --git a/src/images/w3w.png b/src/images/w3w.png new file mode 100644 index 0000000..01b78e2 Binary files /dev/null and b/src/images/w3w.png differ diff --git a/src/index.ts b/src/index.ts index d567049..4640da0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,6 +26,7 @@ export const showLocation = async ({ latitude, longitude, address, + words, sourceLatitude, sourceLongitude, appleIgnoreLatLon, @@ -52,6 +53,7 @@ export const showLocation = async ({ latitude, longitude, address, + words, googleForceLatLon, googlePlaceId, title: customTitle, @@ -135,6 +137,7 @@ export const showLocation = async ({ sourceLng, sourceLatLng, address: fullAddress, + words, title, encodedTitle, prefixes, diff --git a/src/type.ts b/src/type.ts index 74060c9..a1c12aa 100644 --- a/src/type.ts +++ b/src/type.ts @@ -24,7 +24,8 @@ export type MapId = | 'dgis' | 'liftago' | 'petalmaps' - | 'sygic'; + | 'sygic' + | 'w3w'; export type DirectionMode = 'car' | 'walk' | 'public-transport' | 'bike'; @@ -50,6 +51,7 @@ export interface ShowLocationProps { /** optionally you can enter a full address that will be queried against the map app's API and return the initial results if not the actual matched result. */ /** latitude and longitude will be ignored if the address field is set */ address?: string | null; + words?: string | null; sourceLatitude?: number | null; sourceLongitude?: number | null; appleIgnoreLatLon?: boolean; diff --git a/src/utils.ts b/src/utils.ts index 89a992f..4696bc4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -175,6 +175,7 @@ export const checkOptions = ({ latitude, longitude, address, + words, googleForceLatLon, googlePlaceId, title, @@ -186,6 +187,7 @@ export const checkOptions = ({ latitude?: number | string; longitude?: number | string; address?: string | null; + words?: string | null; googleForceLatLon?: boolean | null | undefined; googlePlaceId?: number | string | null | undefined; title?: string | null | undefined; @@ -202,6 +204,9 @@ export const checkOptions = ({ if (address && typeof address !== 'string') { throw new MapsException('Option `address` should be of type `string`.'); } + if (words && typeof words !== 'string') { + throw new MapsException('Option `words` should be of type `string`.'); + } if (title && typeof title !== 'string') { throw new MapsException('`title` should be of type `string`.'); } @@ -244,6 +249,7 @@ export const generateMapUrl = ({ sourceLng, sourceLatLng, address, + words, title, encodedTitle, prefixes, @@ -262,6 +268,7 @@ export const generateMapUrl = ({ sourceLng?: number; sourceLatLng?: string; address?: string | null; + words?: string | null; title?: string | null; encodedTitle?: string; prefixes: Record; @@ -556,6 +563,16 @@ export const generateMapUrl = ({ url = `${prefixes.sygic}coordinate|${lng}|${lat}|`; } url += sygicDirectionsMode ? `${sygicDirectionsMode}` : ''; + break; + case 'w3w': + // w3w only supports passing the 3 word reference or the current user location + // https://developer.what3words.com/tutorial/mobile-linking-to-the-what3words-app#supported-uris + if (words) { + url = `${prefixes.w3w}show?threewords=${words}`; + } else { + url = `${prefixes.w3w}show?currentlocation`; + } + break; } diff --git a/tests/index.test.ts b/tests/index.test.ts index 0e039c8..f856b10 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -634,4 +634,28 @@ describe('showLocation', () => { ); }); }); + describe('w3w', () => { + it('opens with correct url if address is not provided', () => { + verifyThatSettingsLeadToUrl( + { + latitude, + longitude, + app: 'w3w', + }, + 'w3w://show?currentlocation', + ); + }); + + it('opens with correct url if address (w3w) is provided', () => { + verifyThatSettingsLeadToUrl( + { + latitude, + longitude, + app: 'w3w', + words: 'test.three.words', + }, + 'w3w://show?threewords=test.three.words', + ); + }); + }); });