Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

</details>

Expand Down Expand Up @@ -85,6 +86,7 @@ Just add this in your `Info.plist` depending on which apps you'd like to support
<string>dgis</string>
<string>lftgpas</string>
<string>sygic</string>
<string>w3w</string>
</array>
```

Expand Down Expand Up @@ -205,6 +207,10 @@ You can do so by coping the `<queries>` statement below, and pasting it in the t
<action android:name="android.intent.action.VIEW" />
<data android:scheme="com.sygic.aura" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="com.what3words.android" />
</intent>
</queries>
```

Expand Down Expand Up @@ -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)
Expand All @@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const generatePrefixes = ({
liftago: 'lftgpas://',
petalmaps: 'petalmaps://',
sygic: 'com.sygic.aura://',
w3w: 'w3w://',
};
};

Expand Down Expand Up @@ -70,6 +71,7 @@ export const generateTitles = (
liftago: 'Liftago',
petalmaps: 'Petal Maps',
sygic: 'Sygic',
w3w: 'What3Words',
...(titles || {}),
};
};
Expand Down Expand Up @@ -98,6 +100,7 @@ export const icons: Record<string, number> = {
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);
Expand Down
Binary file added src/images/w3w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const showLocation = async ({
latitude,
longitude,
address,
words,
sourceLatitude,
sourceLongitude,
appleIgnoreLatLon,
Expand All @@ -52,6 +53,7 @@ export const showLocation = async ({
latitude,
longitude,
address,
words,
googleForceLatLon,
googlePlaceId,
title: customTitle,
Expand Down Expand Up @@ -135,6 +137,7 @@ export const showLocation = async ({
sourceLng,
sourceLatLng,
address: fullAddress,
words,
title,
encodedTitle,
prefixes,
Expand Down
4 changes: 3 additions & 1 deletion src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export type MapId =
| 'dgis'
| 'liftago'
| 'petalmaps'
| 'sygic';
| 'sygic'
| 'w3w';

export type DirectionMode = 'car' | 'walk' | 'public-transport' | 'bike';

Expand All @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const checkOptions = ({
latitude,
longitude,
address,
words,
googleForceLatLon,
googlePlaceId,
title,
Expand All @@ -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;
Expand All @@ -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`.');
}
Expand Down Expand Up @@ -244,6 +249,7 @@ export const generateMapUrl = ({
sourceLng,
sourceLatLng,
address,
words,
title,
encodedTitle,
prefixes,
Expand All @@ -262,6 +268,7 @@ export const generateMapUrl = ({
sourceLng?: number;
sourceLatLng?: string;
address?: string | null;
words?: string | null;
title?: string | null;
encodedTitle?: string;
prefixes: Record<string, string>;
Expand Down Expand Up @@ -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;
}

Expand Down
24 changes: 24 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
});
});
});