Content-Length: 636273 | pFad | http://github.com/NativeScript/plugins/commit/b88de93c5d835da9a1d9fa479d5e42c6a3de2c86

EA chore(directions): README improvements (#404) [skip ci] · NativeScript/plugins@b88de93 · GitHub
Skip to content

Commit b88de93

Browse files
authored
chore(directions): README improvements (#404) [skip ci]
1 parent 34a8613 commit b88de93

File tree

1 file changed

+57
-88
lines changed

1 file changed

+57
-88
lines changed

packages/directions/README.md

+57-88
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,53 @@
11
# @nativescript/directions
2+
<!-- TODO: Add Preview -->
3+
## Installation
24

35
```cli
46
npm install @nativescript/directions
57
```
68

79
## Usage
10+
### Importing
11+
Once you have installed the plugin, import and create an instance of the `Directions` class.
12+
```ts
13+
import { Directions } from "@nativescript/directions"
814

9-
### Demo app (XML + TypeScript)
10-
11-
Want to dive in quickly? Check out [the demo app](https://github.com/EddyVerbruggen/nativescript-directions/tree/9a9f1ff0de551c447a87b3513a5453f1b962c33c/demo)! Otherwise, continue reading.
12-
13-
You can run the demo app from the root of the project by typing `npm run demo.ios.device` or `npm run demo.android`.
14-
15-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-directions/master/media/directions-animated.gif" width="320px" height="570px"/>
16-
17-
### Demo app (Angular)
18-
19-
This plugin is part of the [plugin showcase app](https://github.com/EddyVerbruggen/nativescript-pluginshowcase/tree/master/app/mapping) I built using Angular.
20-
21-
## API
22-
23-
### `available`
24-
25-
Not all devices have the Google (Android) or Apple (iOS) Maps app installed. Well, most do of course, but on an Android simulator you may be out of luck, so let's check beforehand:
26-
27-
##### JavaScript
28-
29-
```js
30-
// require the plugin
31-
var directions = require('@nativescript/directions');
32-
33-
// instantiate the plugin
34-
var directions = new directions.Directions();
35-
36-
directions.Directions.available().then(function (avail) {
37-
console.log(avail ? 'Yes' : 'No');
38-
});
15+
const directions = new Directions()
3916
```
4017

41-
##### TypeScript
42-
43-
```typescript
44-
// require the plugin
45-
import { Directions } from '@nativescript/directions';
18+
### Checking for support
4619

47-
// instantiate the plugin
48-
let directions = new Directions();
20+
To check if the device has a Maps application installed, call the `available` method.
21+
```ts
22+
directions.available().then((avail:boolean) => {
4923

50-
directions.available().then((avail) => {
5124
console.log(avail ? 'Yes' : 'No');
5225
});
5326
```
54-
55-
### `navigate`
56-
57-
This function opens the native Maps app with a predefined `from` and `to` address.
58-
59-
If you don't pass `from` the current location of the user will be used.
60-
61-
If an `address` is specified then `lat` and `lng` will be ignored.
62-
63-
If you pass in an Array of `to` addresses, then the last item is the destination, the others become 'waypoints'.
64-
65-
Note that if there's an ocean in between `from` and `to` you won't be able to get directions, don't blame this plugin for that 😁
66-
67-
##### JavaScript
68-
69-
```js
70-
directions
71-
.navigate({
72-
from: {
73-
// optional, default 'current location'
74-
lat: 52.215987,
75-
lng: 5.282764,
76-
},
77-
to: {
78-
// either pass in a single object or an Array (see the TypeScript example below)
79-
address: 'Hof der Kolommen 34, Amersfoort, Netherlands',
80-
},
81-
// for platform-specific options, see the TypeScript example below.
82-
})
83-
.then(
84-
function () {
85-
console.log('Maps app launched.');
86-
},
87-
function (error) {
88-
console.log(error);
89-
}
90-
);
91-
```
92-
93-
##### TypeScript
94-
27+
To open the Google (Android) or Apple (iOS) Maps app with the desired directions, call the `navigate` method.
9528
```typescript
9629
directions
9730
.navigate({
9831
from: {
99-
// optional, default 'current location'
10032
lat: 52.215987,
10133
lng: 5.282764,
10234
},
10335
to: [
10436
{
105-
// if an Array is passed (as in this example), the last item is the destination, the addresses in between are 'waypoints'.
10637
address: 'Hof der Kolommen 34, Amersfoort, Netherlands',
10738
},
10839
{
10940
address: 'Aak 98, Wieringerwerf, Netherlands',
11041
},
11142
],
112-
type: 'walking', // optional, can be: driving, transit, bicycling or walking
43+
type: 'walking',
11344
ios: {
114-
preferGoogleMaps: true, // If the Google Maps app is installed, use that one instead of Apple Maps, because it supports waypoints. Default true.
115-
allowGoogleMapsWeb: true, // If waypoints are passed in and Google Maps is not installed, you can either open Apple Maps and the first waypoint is used as the to-address (the rest is ignored), or you can open Google Maps on web so all waypoints are shown (set this property to true). Default false.
116-
useUniversalSyntax: true, // Prefer the Universal URL Syntax to the comgooglemaps:// url scheme. Useful if Google Maps does not load correctly.
45+
preferGoogleMaps: true,
46+
allowGoogleMapsWeb: true,
47+
useUniversalSyntax: true,
11748
},
11849
android: {
119-
newTask: true, // Start as new task. This means it will start a new history stack instead of using the current app. Default true.
50+
newTask: true,
12051
},
12152
})
12253
.then(
@@ -129,9 +60,47 @@ directions
12960
);
13061
```
13162

132-
## Future work
63+
## API
64+
### Method(s)
65+
66+
| Name | Return Type | Description |
67+
|------|-------------|-------------|
68+
| `available()` | `Promise<boolean>` | Checks if the device has the Maps application installed. |
69+
| `navigate(options: NavigateToOptions)`| `Promise<void>` | Opens the native Maps app with a predefined `from` and `to` address and [other](#navigatetooptions) optional settings.|
70+
71+
### AddressOptions
72+
| Name| Type | Description|
73+
|-----|------|------------|
74+
| `lat` | `number` | _Optional_: The latitude. Ignored if `address`' is set.|
75+
| `lng` | `number` | _Optional_: The longitude. Ignored if `address`' is set. |
76+
| `address` | `string` | _Optional_: The address of the direction. For multiple addresses, add them to the string separating them with a comma.|
77+
78+
### NavigateToOptionsType
79+
```ts
80+
'driving' | 'transit' | 'bicycling' | 'walking'
81+
```
13382

134-
- Perhaps add Android-specific options like opening the map in StreetView mode, or pre-defining the transportation type (walk/bike/car).
83+
### NavigateToOptions
84+
| Name| Type | Description|
85+
|-----|------|------------|
86+
| `from`| [AddressOptions](#addressoptions)| _Optional_: The starting point for the navigation. <br><br>If this option is not passed, the current location of the user will be used.|
87+
| `to` | [AddressOptions](#addressoptions) \| Array<[AddressOptions](#addressoptions)>| The destination of the navigation. If it's an array of addresses, then the last item is the destination, the others become 'waypoints'.|
88+
| `ios` | [iOSOptions](#iosoptions) | _Optional_: iOS-specific settings. |
89+
| `android` | [AndroidOptions](#androidoptions) | _Optional_: Android-specific settings. |
90+
| `useUniversalSyntax` | `boolean` | _Optional_: If `true`, this opens Google Maps using the universal syntax rather than the comgooglemaps:// url scheme. Use this if Google Maps does not load correctly on iOS, the Universal Syntax is now preferred.|
91+
| `type` | [NavigateToOptionsType](#navigatetooptionstype) | _Optional_: The mode of reaching to the destionation. |
92+
93+
>**Note** that if there's an ocean in between `from` and `to` you won't be able to get directions, don't blame this plugin for that 😁.
94+
### iOSOptions
95+
| Name| Type | Description|
96+
|-----|------|------------|
97+
| `preferGoogleMaps`| `boolean`| _Optional_: Indicates whether to use Google Maps(if installed) instead of the iOS Maps. You might want to use Google Maps app because it supports waypoints.|
98+
| `allowGoogleMapsWeb`| `boolean` | If waypoints are passed in and Google Maps is not installed, you can either open Apple Maps and the first waypoint is used as the to-address (the rest is ignored), or you can set this option to `true` to open Google Maps on web so all waypoints are shown.|
99+
100+
### AndroidOptions
101+
| Name| Type | Description|
102+
|-----|------|------------|
103+
| `newTask` | `boolean` | _Optional_: Indicates whether to start directions as new task.|
135104

136105
## License
137106

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/plugins/commit/b88de93c5d835da9a1d9fa479d5e42c6a3de2c86

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy