Giter Club home page Giter Club logo

nativescript-directions's Introduction

NativeScript Directions plugin

NPM version Downloads Twitter Follow

โš ๏ธ Looking for NativeScript 7 compatibilty? Go to the NativeScript/plugins repo.

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 plugin
var Directions = require("nativescript-directions").Directions;

// instantiate the plugin
var directions = new Directions();

directions.available().then(
  function(avail) {
    console.log(avail ? "Yes" : "No");
  }
);
TypeScript
// require the plugin
import { Directions } from "nativescript-directions";

// instantiate the plugin
let directions = new Directions();

directions.available().then(avail => {
    console.log(avail ? "Yes" : "No");
});

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.navigate({
  from: { // optional, default 'current location'
    lat: 52.215987,
    lng: 5.282764
  },
  to: { // either pass in a single object or an Array (see the TypeScript example below)
    address: "Hof der Kolommen 34, Amersfoort, Netherlands"
  }
  // for platform-specific options, see the TypeScript example below.
}).then(
  function() {
    console.log("Maps app launched.");
  },
  function(error) {
    console.log(error);
  }
);
TypeScript
directions.navigate({
  from: { // optional, default 'current location'
    lat: 52.215987,
    lng: 5.282764
  },
  to: [{ // if an Array is passed (as in this example), the last item is the destination, the addresses in between are 'waypoints'.
    address: "Hof der Kolommen 34, Amersfoort, Netherlands",
  },
  {
    address: "Aak 98, Wieringerwerf, Netherlands"
  }],
  type: "walking", // optional, can be: driving, transit, bicycling or walking
  ios: {
    preferGoogleMaps: true, // If the Google Maps app is installed, use that one instead of Apple Maps, because it supports waypoints. Default true.
    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.
  },
  android: {
    newTask: true // Start as new task. This means it will start a new history stack instead of using the current app. Default true.
  }
}).then(() => {
    console.log("Maps app launched.");
}, error => {
    console.log(error);
});

Future work

  • Perhaps add Android-specific options like opening the map in StreetView mode, or pre-defining the transportation type (walk/bike/car).

nativescript-directions's People

Contributors

bradmartin avatar eddyverbruggen avatar pietcompenda avatar spiegelberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nativescript-directions's Issues

Lat, Long for to address

Hi Eddy,

Can I pass Lat and Long to the to: array instead of an address, or in conjunction with an address? How would I do this and which one will be used as default?

Demo App: Clicking on any of the buttons does nothing

I cloned the repo and went into the demo folder and installed the node dependencies. I am able to successfully run both the android and iOS builds (npm run start-android-bundle and npm run start-ios-bundle) but when I try to click on any of the buttons nothing happens. Are there any additional steps I need to take to get this working? Like adding a google API key?

screen shot 2018-10-05 at 12 33 25 pm

Feature request - add support in waze

Hi @EddyVerbruggen

There is a chance to add waze to the support GPS applications on this plugin.
Actually to be more specific, it would be awesome to make the user choose between the available support GPS apps.

Thanks! :)

TypeError: Cannot read property 'startActivityForResult' of undefined

TypeError: Cannot read property 'startActivityForResult' of undefined 

I get this error anytime i try to execute this code.. surprisingly it was working before
@EddyVerbruggen help me out

           directions.navigate({
                to: this.nearByCustomers// array of coordinates,
                type: "driving",
                ios: {
                    preferGoogleMaps: true, 
                    allowGoogleMapsWeb: true 
                }
                }).then(() => {
                    console.log("Maps app launched.");
                }, error => {
                    console.log(error);
            });

Optimize way points

When executing the navigate() method, it would be nice to be able to pass an "optimizeWaypoints" parameter. When i set the 'to' property to an array of addresses, it just calculates the route according to the order of the array, which is not always the optimal route.

preferGoogleMaps is not working

I set preferGoogleMaps: true, in iOS options but it doesnt open Google Maps App (Google Maps is installed) instead it opens iOS Maps App.

Maybe I am wrong, help me please :D

PD: Only when I set an array in to: it opens Google Maps with way points (I think this is because open the web url)

Issue while using in angular 6

I am getting this error - while trying to add this module in angular 6 component.

Module not found: Error: Can't resolve 'nativescript-directions'

I did install the plugin in my app using :, also i can see this in my node modules folder.
tns plugin add nativescript-directions

this is the exact error :
ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve 'nativescript-directions' in 'D:\projects\ng-maps\src\app'
ERROR in ./src/app/directions/directions.component.ts
Module not found: Error: Can't resolve 'nativescript-directions' in 'D:\projects\ng-maps\src\app\directions'

in app.module.ts i have imported like this
import { Directions } from "nativescript-directions";

In IDE , It is not showing any errors.

Any inputs pls.

Unchaught Exception occurred

Hi,

I'm pretty new to nativescript, but i'm running into this error and have no clue why.
I've just ran the demo app and it doesn't seem to work

image

image

What seems to be the problem?

Release 1.4 not published on npm

Thanks for the quick pick-up of my PR. I saw you created a release for it too, but it seems it isn't published to npm yet. Is this correct?

Problem with current location

Hi, I've a problem when I'm using the default "from" (current location).
The problem is when maps app start, it doesn't automatically recognize my current location generating an error.
There's a screenshot of what I'm trying to explain. Thanks

photo_2017-10-27_15-48-14

Directions.available bug

Hello everybody,

Today I'm working on a navigation app, and we use @nativescript/directions 2.0.2.

Since our last upgrade, Directions.available() returns false, but it should return true, and when (for testing) we call directly Directions.navigate(), the navigation app opens correctly.

let directions = new Directions();
directions.available().then(available => {
    console.log({ available })             // return false
    if (true) {                            // force to enter and it
        directions.navigate({              // it works despite the available = false !!!
            to: {
                lat: parseFloat(this.totem.latitude),
                lng: parseFloat(this.totem.longitude),
            }
        }).then(() => { }, () => {
            GlobalService.toast(localize('app.gps_unavailable'));
        });
    } else {
        GlobalService.toast(localize('app.gps_unavailable'));
    }
});

Can you help me please ?
Best regards

Open waze app

I want that this plugin will open me waze app, if available.
But it always open google maps app, and not waze.
What can I do?

Error after installed web pack

I've installed web pack on my project and then i'm getting the following error.

ERROR in ./modules/pack.address/pack.address.component.ts
Module not found: Error: Can't resolve 'nativescript-directions' in 'C:\dev\fm-transportes\src\FM.Transportes\app\modules\pack.address'
@ ./modules/pack.address/pack.address.component.ts 13:17-51
@ ./app.module.ts
@ ./main.ts

pack.address.component.ts

import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { DatabaseService, Package, Pack, Order, Address, PackStatus, State } from '../shared';
let Directions = require("nativescript-directions").Directions;

@Component({
    moduleId: module.id,
    selector: 'pack-address',
    templateUrl: './pack.address.component.html',
    styleUrls: ['./pack.address.component.css'],
})
export class PackAddressComponent {
...

Is the nativescript-directions plugin compatible ?
I also opened an issue on the web pack page
#NativeScript/nativescript-dev-webpack#81

Android - Opening Map App instead of URL on top of my app

I can't seem to find a way with the current setup of this api to open the actual Google Maps app on an android phone. It opens the maps link over the app that I am trying to navigate from. Hopefully I am explaining that correctly. I am wondering if you could add an option to default opening the app on android (like how it works in the ios code)?

How to set Google Maps as default app

Hi, I was able to include and run the plugin in the Android emulator (it works nicely by the way), but I noticed that upon calling Directions.navigate(), I was asked if I should open with: Maps or Browser

Is there any way to direct navigation to Maps only (and not show other app options?)

Not even sure if this can be controlled/set through the plugin alone

Opens DB Navigator instead of Google Maps

When I run this plugin ("nativescript-directions": "^1.3.1") on an Android emulator (Galaxy_Nexus_API_29) it works fine. But when I run it on a physical device via tns preview (Galaxy S8), it opens a totally different app, the german railway app "DB Navigator". Also it doesn't pass the address to the app, but the current date + time. Why does this happen?

Can't run demo

Hi there,

I tried to run the demo off the bat like you suggest npm run demo.ios.device and i get the following:

error TS6053: File 'node_modules/tns-platform-declarations/tns-core-modules/android17.d.ts' not found.
error TS6053: File 'node_modules/tns-platform-declarations/tns-core-modules/ios/ios.d.ts' not found.
error TS6053: File 'node_modules/tns-platform-declarations/tns-core-modules/org.nativescript.widgets.d.ts' not found.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/manuelmaestrini/.npm/_logs/2017-07-09T01_50_15_572Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] preparedemo: `npm run build && cd demo && tns plugin remove nativescript-directions && tns plugin add .. && tns install`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] preparedemo script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/manuelmaestrini/.npm/_logs/2017-07-09T01_50_15_600Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] demo.ios.device: `npm run preparedemo && cd demo && tns run ios`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] demo.ios.device script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/manuelmaestrini/.npm/_logs/2017-07-09T01_50_15_628Z-debug.log

Any idea what is the issue?

I tried to run the demo directly from the demo folder, by following what in a closed issue here was outlined by removing the directions package, re installing it and running then the app. All worked until the app loaded. It crashed immediately and the error output is

Successfully synced application com.nordsense.waste-realtime on device 9368C117-25DB-4481-8AA0-A055B0B11BB6.

1   0x10c2238d7 -[TNSRuntime executeModule:]
2   0x10bdbc532 main
3   0x11013065d start
file:///app/app.js:3:26: JS ERROR Error: Could not find module 'application'. Computed path '/Users/manuelmaestrini/Library/Developer/CoreSimulator/Devices/9368C117-25DB-4481-8AA0-A055B0B11BB6/data/Containers/Bundle/Application/AC229060-7CA9-47A3-9471-6157787F51F6/demo.app/app/tns_modules/application'.
Jul  9 05:13:34 Manuels-MacBook-Pro-4 com.apple.CoreSimulator.SimDevice.9368C117-25DB-4481-8AA0-A055B0B11BB6.launchd_sim[56930] (UIKitApplication:com.xxxx.xxxx[0x89fe][56952][57226]): Service exited due to Segmentation fault: 11 ```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.