Geolocation import unused?

Hello Ionic!

I am trying to add a google map and use the geolocation ionic native plugin for geolocation. This is the .ts:

import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Geolocation } from 'ionic-native';

declare var google: any;

@Component({
  selector: 'map-page',
  templateUrl: 'map.html'
})

export class MapPage {

  @ViewChild('map') mapElement: ElementRef;
  map: any;

  constructor(public navCtrl: NavController) {

  if (navigator.geolocation) {

     var options = {
      enableHighAccuracy: true //google maps js geolocation was way off
      };

      navigator.geolocation.getCurrentPosition(position=> {
        console.info('using navigator');
        console.info(position.coords.latitude);
        console.info(position.coords.longitude);
        let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        
        this.map = new google.maps.Map(this.mapElement.nativeElement);

        new google.maps.Marker({
              map: this.map,
              position: latLng
            });
        }, error => {
          console.log(error);
        }, options);
        }
    }
  }

Everything seems to work fine. When I run it on my phone, GPS is activated and accuracy seems good.

But whenever I serve or build there is an error message “Geolocation import unused”…

What does this mean? I’m obviously using native geolocation…

Thanks!

That you’re not using actually the ionic-native Geolocation shim that you bothered to import. You’re going behind its back and directly accessing things via navigator.

Is this a correct approach?

I needed highAccuracy and this method ended up giving me the best results…
Should I leave it like this and uninstall ionic geolocation plugin?

Thanks!

It looks to me like highAccuracy is supported by ionic-native. My rule of thumb is that it is always better to use ionic-native, because it handles all the integration with Angular change detection and wraps things in Promises and Observables, which fit much more nicely into Angular apps than do the unwieldy callbacks of direct Cordova access.

OK thanks!

I will just get rid off all of those navigator.

Cheers!