0

In my understanding all the ionic native plugins should only work on a real device, or the browser when served via cordova run.

But I see, that the geolocation plugin works with ionic serve as well and I'm wondering now why and if this is possible with other plugins, file i.e as well.

An excerpt of my app.modules

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { File } from '@ionic-native/file/ngx';


@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule],
  providers: [
    StatusBar,
    File,
    Geolocation,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

How I call geolocation

import { Geolocation } from '@ionic-native/geolocation/ngx';
import { File } from '@ionic-native/file/ngx';

@Component({
  selector: 'page-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage{
  constructor(
    private geolocation: Geolocation,
    private file: File,
) {
this.geolocation.getCurrentPosition()
this.file.getFreeDiskSpace()
  }
}
Flo
  • 2,699
  • 4
  • 24
  • 46

1 Answers1

0

You should always see the platforms supported by the plugin in Ionic Doc.

this plugin supports these platforms :

  • Amazon Fire OS
  • Android
  • Browser
  • iOS
  • Windows

This plugin provides information about the device's location, such as latitude and longitude. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs.

Kilomat
  • 125
  • 10
  • Yes, but `file` for instance is supporting browser as well, but doesn't work with `ionic serve` – Flo Oct 21 '18 at 10:19
  • Yes, not all plugin. About the plugin file, you can find this issue here https://stackoverflow.com/questions/37892253/how-to-save-file-locally-in-apache-cordova-using-file-plugin. – Kilomat Oct 22 '18 at 12:09