Skip to content

Commit

Permalink
Merge pull request #272 from trevorrd/master
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoffelen authored May 14, 2024
2 parents 3bf488a + c2c8378 commit 7cd754d
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 94 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ showLocation({
latitude: 38.8976763,
longitude: -77.0387185,
sourceLatitude: -8.0870631, // optionally specify starting location for directions
sourceLongitude: -34.8941619, // not optional if sourceLatitude is specified
title: 'The White House', // optional
sourceLongitude: -34.8941619, // required if sourceLatitude is specified
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,12 +265,23 @@ showLocation({
});
```

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';

showLocation({
address: '1600 Pennsylvania Avenue NW, Washington, DC 20500', // Required if replacing latitude and longitude
app: 'comgooglemaps', // optionally specify specific app to use
});
```

Notes:

- The `sourceLatitude` / `sourceLongitude` options only work if you specify both. Currently supports all apps except Waze.
- `directionsMode` works on google-maps, apple-maps and sygic (on apple-maps, `bike` mode will not work, while on sygic, only `walk` and `car` will work). Without setting it, the app will decide based on its own settings.
- If you set `directionsMode` but do not set `sourceLatitude` and `sourceLongitude`, google-maps and apple-maps will still enter directions mode, and use the current location as starting point.
-
- If you want to query an address instead of passing the `latitude` and `longitude` fields, you can do this by leaving those fields off and provide a full address to be queried with the `address` field. Just be aware that not all applications support this.

### Or

Expand All @@ -296,6 +307,7 @@ const Demo = () => {
const result = await getApps({
latitude: 38.8976763,
longitude: -77.0387185,
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-map-link",
"version": "3.0.1",
"version": "3.1.0",
"description": "Open the map app of the user's choice with a specific location.",
"source": "src/index",
"main": "lib/index.js",
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type {PopupProps} from './components/popup/Popup';
export const showLocation = async ({
latitude,
longitude,
address,
sourceLatitude,
sourceLongitude,
appleIgnoreLatLon,
Expand All @@ -49,6 +50,7 @@ export const showLocation = async ({
checkOptions({
latitude,
longitude,
address,
googleForceLatLon,
googlePlaceId,
title: customTitle,
Expand All @@ -62,6 +64,7 @@ export const showLocation = async ({
let sourceLat;
let sourceLng;
let sourceLatLng;
let fullAddress;

if (sourceLatitude != null && sourceLongitude != null) {
useSourceDestiny = true;
Expand All @@ -76,6 +79,10 @@ export const showLocation = async ({
sourceLatLng = `${sourceLat},${sourceLng}`;
}

if (address) {
fullAddress = encodeURIComponent(address);
}

const lat = typeof latitude === 'string' ? parseFloat(latitude) : latitude;
const lng = typeof longitude === 'string' ? parseFloat(longitude) : longitude;
const latlng = `${lat},${lng}`;
Expand Down Expand Up @@ -121,6 +128,7 @@ export const showLocation = async ({
sourceLat,
sourceLng,
sourceLatLng,
address: fullAddress,
title,
encodedTitle,
prefixes,
Expand Down
7 changes: 5 additions & 2 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ export type GetAppsResponse = {
};

export interface ShowLocationProps {
latitude: number | string;
longitude: number | string;
latitude?: number | string;
longitude?: number | string;
/** 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;
sourceLatitude?: number | null;
sourceLongitude?: number | null;
appleIgnoreLatLon?: boolean;
Expand Down
Loading

0 comments on commit 7cd754d

Please sign in to comment.