NativeScript Directions plugin
Installation
From the command prompt go to your app's root folder and execute:
tns plugin add nativescript-directions
Usage
Demo app (XML + TypeScript)
Want to dive in quickly? Check out the demo app! Otherwise, continue reading.
You can run the demo app from the root of the project by typing npm run demo.ios.device
or npm run demo.android
.
Demo app (Angular)
This plugin is part of the plugin showcase app I built using Angular.
API
available
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:
JavaScript
// require the pluginvar Directions = Directions; // instantiate the pluginvar directions = ; directions;
TypeScript
// require the plugin; // instantiate the plugin; directions.available.then;
navigate
This function opens the native Maps app with a predefined from
and to
address.
If you don't pass from
the current location of the user will be used.
If an address
is specified then lat
and lng
will be ignored.
If you pass in an Array of to
addresses, then the last item is the destination, the others become 'waypoints'.
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 😁
JavaScript
directions;
TypeScript
directions.navigate.then, ;
Future work
- Perhaps add Android-specific options like opening the map in StreetView mode, or pre-defining the transportation type (walk/bike/car).