From 31981763f7a8d1290c5643ef868a37bd49356060 Mon Sep 17 00:00:00 2001 From: Luke <66969275+lcorbett89@users.noreply.github.com> Date: Sat, 15 Mar 2025 08:43:56 +0000 Subject: [PATCH 1/4] Add what3words support --- README.md | 23 ++++++++++++++++++++--- src/constants.ts | 3 +++ src/images/w3w.png | Bin 0 -> 9998 bytes src/type.ts | 3 ++- src/utils.ts | 10 ++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 src/images/w3w.png diff --git a/README.md b/README.md index 6933cfd..bfc0135 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,17 @@ showLocation({ }); ``` +When using the whatThreeWords app, only the 3 words should be used in the `address` field instead of the `latitude` and `longitude` properties. + +```js +import {showLocation} from 'react-native-map-link'; + +showLocation({ + address: 'daring.lion.race', // 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 +324,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 0000000000000000000000000000000000000000..01b78e21494f06920f6aec1c883ae6ec91a0503c GIT binary patch literal 9998 zcmd^lby%C-vTyL90g4wZTHLi*aQ8xRr?@-Ct++ds;O^4m5WGmyLMiSpEyd;1{q3{& zclSBx@B7Dn^Q?Df&CG9R&1ACH`y`1}RhGd-BS8ZI0GM*JlIqVi?au%rKi`GmoHw2c z;ybVs7yzh`N53~gdY)67$*L;>06ug8Kwu~UaQiF@+yemI*#Uq9V*o%f0{|d&%4t&* zdRC-aK;$fylmLv+JP?2chYLV>=HQ-R05}rBA8*ebKpyVpzj$>x4gmbK4Ci_1Mpy$7 z|7m0QOrI~ry64+7<}d2$>B(yCVC!mT;$*?<=<@DahX959cMK@}zwl{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RtGe+4i~*9)-wZZitz)U{&=%OORRWFaDL%(H*hpn=yIN_UHtS$MfNiC z)U>c(YwV(rf2zI{*Z7<~i@szpM~MEWFGB1z1&^bxi34?lZ^9^)?l9oqd8BtscT_7{ z%D%YhJ(8H#1vHUeHnF#9tG(_Lr<@C;Qj)IlYb*0N2@m8!xW7tMKO^%NAiM;k#pq7Ifvh_91Ijt4pjL_fvSW zC}rH6dtzKSadBKtg|Tbp1HzoYo6DW zK_ln9GF5pYKoRCW!d$PN8}zGudZjoQR2VYDniUxyr)D-ldX@o^04;sDcF^0yhUB4q z-&q1%3e@z$z|a4JOxrWuFaIe;;>q|n72zu-TjWo$4W(+L+Hbfjm&7^wx^3<+-9`#N zh=jePU|{ci7VGq@8`!9;C|v*m literal 0 HcmV?d00001 diff --git a/src/type.ts b/src/type.ts index 74060c9..7a7e98c 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'; diff --git a/src/utils.ts b/src/utils.ts index 89a992f..a910c42 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -556,6 +556,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 (address) { + url = `${prefixes.w3w}show?threewords=${address}`; + } else { + url = `${prefixes.w3w}show?currentlocation`; + } + break; } From d52cc0ff6b3b44a5ffe36d58aeede9fceed8682a Mon Sep 17 00:00:00 2001 From: Luke <66969275+lcorbett89@users.noreply.github.com> Date: Sat, 15 Mar 2025 22:59:20 +0000 Subject: [PATCH 2/4] add tests --- tests/index.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/index.test.ts b/tests/index.test.ts index 0e039c8..c90a90d 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -634,4 +634,26 @@ 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( + { + app: 'w3w', + address: 'test.three.words', + }, + 'w3w://show?threewords=test.three.words', + ); + }); + }); }); From 39e7ad24482f4b1d4b1b1598f00d7f019177747a Mon Sep 17 00:00:00 2001 From: Luke <66969275+lcorbett89@users.noreply.github.com> Date: Sat, 15 Mar 2025 23:40:44 +0000 Subject: [PATCH 3/4] add 'words' field instead of using 'address' as this breaks apple maps directions --- src/index.ts | 3 +++ src/type.ts | 1 + src/utils.ts | 11 +++++++++-- tests/index.test.ts | 4 +++- 4 files changed, 16 insertions(+), 3 deletions(-) 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 7a7e98c..a1c12aa 100644 --- a/src/type.ts +++ b/src/type.ts @@ -51,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 a910c42..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; @@ -560,8 +567,8 @@ export const generateMapUrl = ({ 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 (address) { - url = `${prefixes.w3w}show?threewords=${address}`; + if (words) { + url = `${prefixes.w3w}show?threewords=${words}`; } else { url = `${prefixes.w3w}show?currentlocation`; } diff --git a/tests/index.test.ts b/tests/index.test.ts index c90a90d..f856b10 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -649,8 +649,10 @@ describe('showLocation', () => { it('opens with correct url if address (w3w) is provided', () => { verifyThatSettingsLeadToUrl( { + latitude, + longitude, app: 'w3w', - address: 'test.three.words', + words: 'test.three.words', }, 'w3w://show?threewords=test.three.words', ); From b581f18ce155df65ac38a34f9daf29b69ae001b2 Mon Sep 17 00:00:00 2001 From: Luke <66969275+lcorbett89@users.noreply.github.com> Date: Sun, 16 Mar 2025 00:01:18 +0000 Subject: [PATCH 4/4] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bfc0135..06ab086 100644 --- a/README.md +++ b/README.md @@ -282,13 +282,15 @@ showLocation({ }); ``` -When using the whatThreeWords app, only the 3 words should be used in the `address` field instead of the `latitude` and `longitude` properties. +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({ - address: 'daring.lion.race', // Required if using w3w provider + latitude: 38.8976763, + longitude: -77.0387185, + words: 'rope.noses.canny', // Required if using w3w provider app: 'w3w', // optionally specify specific app to use }); ```