You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`.
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');
To check if the device has a Maps application installed, call the `available` method.
21
+
```ts
22
+
directions.available().then((avail:boolean) => {
49
23
50
-
directions.available().then((avail) => {
51
24
console.log(avail?'Yes':'No');
52
25
});
53
26
```
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.
95
28
```typescript
96
29
directions
97
30
.navigate({
98
31
from: {
99
-
// optional, default 'current location'
100
32
lat: 52.215987,
101
33
lng: 5.282764,
102
34
},
103
35
to: [
104
36
{
105
-
// if an Array is passed (as in this example), the last item is the destination, the addresses in between are 'waypoints'.
106
37
address: 'Hof der Kolommen 34, Amersfoort, Netherlands',
107
38
},
108
39
{
109
40
address: 'Aak 98, Wieringerwerf, Netherlands',
110
41
},
111
42
],
112
-
type: 'walking', // optional, can be: driving, transit, bicycling or walking
43
+
type: 'walking',
113
44
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,
117
48
},
118
49
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,
120
51
},
121
52
})
122
53
.then(
@@ -129,9 +60,47 @@ directions
129
60
);
130
61
```
131
62
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
+
```
133
82
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'.|
|`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.|
0 commit comments