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!