Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.12.0 (issue210-address-as-parameter) - Adding ADDRESS as a potential parameter #272

Merged
merged 16 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ 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
address: '', // optional but can replace latitude and longitude if needed
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 +266,34 @@ 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({
trevorrd marked this conversation as resolved.
Show resolved Hide resolved
latitude: '',
longitude: '',
address: '1600 Pennsylvania Avenue NW, Washington, DC 20500', // Required if replacing latitude and longitude
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)
dialogTitle: 'This is the dialog Title', // optional (default: 'Open in Maps')
dialogMessage: 'This is the amazing dialog Message', // optional (default: 'What app would you like to use?')
cancelText: 'This is the cancel button text', // optional (default: 'Cancel')
appsWhiteList: ['google-maps'], // optionally you can set which apps to show (default: will show all supported apps installed on device)
naverCallerName: 'com.example.myapp', // to link into Naver Map You should provide your appname which is the bundle ID in iOS and applicationId in android.
appTitles: { 'google-maps': 'My custom Google Maps title' }, // optionally you can override default app titles
app: 'uber', // 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 both of the required fields as empty strings and provide a full address to be queried. Just be aware that not all applications support this.

### Or

Expand All @@ -296,6 +319,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
3 changes: 3 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export type GetAppsResponse = {
export interface ShowLocationProps {
latitude: number | string;
trevorrd marked this conversation as resolved.
Show resolved Hide resolved
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