Skip to content

Commit 7cd754d

Browse files
authored
Merge pull request #272 from trevorrd/master
2 parents 3bf488a + c2c8378 commit 7cd754d

File tree

5 files changed

+225
-94
lines changed

5 files changed

+225
-94
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ showLocation({
249249
latitude: 38.8976763,
250250
longitude: -77.0387185,
251251
sourceLatitude: -8.0870631, // optionally specify starting location for directions
252-
sourceLongitude: -34.8941619, // not optional if sourceLatitude is specified
253-
title: 'The White House', // optional
252+
sourceLongitude: -34.8941619, // required if sourceLatitude is specified
253+
title: 'The White House', // optional
254254
googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
255255
googlePlaceId: 'ChIJGVtI4by3t4kRr51d_Qm_x58', // optionally specify the google-place-id
256256
alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)
@@ -265,12 +265,23 @@ showLocation({
265265
});
266266
```
267267

268+
Alternatively you can specify the `address` field and leave the latitude and longitude properties as empty strings
269+
270+
```js
271+
import {showLocation} from 'react-native-map-link';
272+
273+
showLocation({
274+
address: '1600 Pennsylvania Avenue NW, Washington, DC 20500', // Required if replacing latitude and longitude
275+
app: 'comgooglemaps', // optionally specify specific app to use
276+
});
277+
```
278+
268279
Notes:
269280

270281
- The `sourceLatitude` / `sourceLongitude` options only work if you specify both. Currently supports all apps except Waze.
271282
- `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.
272283
- 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.
273-
-
284+
- 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.
274285

275286
### Or
276287

@@ -296,6 +307,7 @@ const Demo = () => {
296307
const result = await getApps({
297308
latitude: 38.8976763,
298309
longitude: -77.0387185,
310+
address: '1600 Pennsylvania Avenue NW, Washington, DC 20500', // optional
299311
title: 'The White House', // optional
300312
googleForceLatLon: false, // optionally force GoogleMaps to use the latlon for the query instead of the title
301313
alwaysIncludeGoogle: true, // optional, true will always add Google Maps to iOS and open in Safari, even if app is not installed (default: false)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-map-link",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "Open the map app of the user's choice with a specific location.",
55
"source": "src/index",
66
"main": "lib/index.js",

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type {PopupProps} from './components/popup/Popup';
2525
export const showLocation = async ({
2626
latitude,
2727
longitude,
28+
address,
2829
sourceLatitude,
2930
sourceLongitude,
3031
appleIgnoreLatLon,
@@ -49,6 +50,7 @@ export const showLocation = async ({
4950
checkOptions({
5051
latitude,
5152
longitude,
53+
address,
5254
googleForceLatLon,
5355
googlePlaceId,
5456
title: customTitle,
@@ -62,6 +64,7 @@ export const showLocation = async ({
6264
let sourceLat;
6365
let sourceLng;
6466
let sourceLatLng;
67+
let fullAddress;
6568

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

82+
if (address) {
83+
fullAddress = encodeURIComponent(address);
84+
}
85+
7986
const lat = typeof latitude === 'string' ? parseFloat(latitude) : latitude;
8087
const lng = typeof longitude === 'string' ? parseFloat(longitude) : longitude;
8188
const latlng = `${lat},${lng}`;
@@ -121,6 +128,7 @@ export const showLocation = async ({
121128
sourceLat,
122129
sourceLng,
123130
sourceLatLng,
131+
address: fullAddress,
124132
title,
125133
encodedTitle,
126134
prefixes,

src/type.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ export type GetAppsResponse = {
4545
};
4646

4747
export interface ShowLocationProps {
48-
latitude: number | string;
49-
longitude: number | string;
48+
latitude?: number | string;
49+
longitude?: number | string;
50+
/** 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. */
51+
/** latitude and longitude will be ignored if the address field is set */
52+
address?: string | null;
5053
sourceLatitude?: number | null;
5154
sourceLongitude?: number | null;
5255
appleIgnoreLatLon?: boolean;

0 commit comments

Comments
 (0)