6

I am new to Ionic 2 and everything around. I'm tryng to setup my first mobile app: touching a button I would open native navigation (Google Maps for Android, for instance). I've installed launchnavigator plugin:

ionic plugin add uk.co.workingedge.phonegap.plugin.launchnavigator

and inside cremony.ts page:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { LaunchNavigator, LaunchNavigatorOptions } from 'ionic-native';

@Component({
  selector: 'page-ceremony',
  templateUrl: 'ceremony.html'
})
export class Ceremony {

  constructor(public navCtrl: NavController) {

  }

  navigate() {
    let options: LaunchNavigatorOptions = {
      start: ""
    };

    LaunchNavigator.navigate("London, UK", options)
      .then(
      success => alert('Launched navigator'),
      error => alert('Error launching navigator: ' + error)
      );
  }
}

make a build npm run buildand upload it to IonicView with ionic upload. I've do everything like suggested in this link but with different luck.

But when I click the button (a simple <button ion-button (click)="navigate()">Navigate</button> in the ceremony.html) in the Ionic View an error say: Error launghing navigator: plugin_not_installed.

I inspected the project, the plugins directory contains uk.co.workingedge.phonegap.plugin.launchnavigatorlooks directory. So I look at package.json and config.xml and I've added the value uk.co.workingedge.phonegap.plugin.launchnavigator in the cordovaPlugins and tag <plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" spec="~3.2.1" /> in the widget root. npm run build, ionic upload but nothing changed.

Where is my error?

BAD_SEED
  • 4,840
  • 11
  • 53
  • 110

3 Answers3

2

New answer, there is something wrong with your project. Have you modified your index.html file? Is it still including cordova.js? If so what version of Ionic and Cordova are you using?

I made this sample application with your exact code and it works perfectly on both iOS and ANdroid: https://github.com/roblouie/navigator-plugin-test

Did a screen recording on iOS: https://giphy.com/gifs/xTiN0EEQV82aIXWnQI Just grabbed an image on Android, but it works the same: Android Pic

Please try the project from github.

Rob Louie
  • 2,462
  • 1
  • 19
  • 24
1

Cordova plugins need to be called only once platform is ready.

constructor(public navCtrl: NavController,public platform:Platform) {//inject in constructor

  }

In your function navigate()

this.platform.ready().then(()=>{
LaunchNavigator.navigate("London, UK", options)
      .then(
      success => alert('Launched navigator'),
      error => alert('Error launching navigator: ' + error)
      );
});
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1

The reason for your error is that you are using Ionic View. Your Ionic app is just html, css, and javascript. However, any plugins you use are written in Java for Android and Objective C for iOS. That plugin source code is then compiled into your app for each platform.

With Ionic View, it only uploads your app, the html, css, and javascript. Nothing is compiled. Ionic View is the app itself, and it loads your code. So no plugins you have are included. Ionic View itself does have some plugins installed on it, and you can see that list here: https://docs.ionic.io/tools/view/#supported-plugins

Unfortunately you will not be able to test any plugin not in that list without building and deploying to a device or emulator.

Rob Louie
  • 2,462
  • 1
  • 19
  • 24
  • I made the `.apk` package (using `ionic build android` command), installed it as a non-trusted package (I haven't store account yet) and when I click the button I get `Error lauching navigator: cordova_not_available` – BAD_SEED Feb 27 '17 at 16:31
  • @marianoc84 Okay interesting...that's a bit concerning actually, Cordova should definitely be available when running on device. I can maybe dig further later today if no one else solves it before then. – Rob Louie Feb 27 '17 at 17:31