import {IonicView} from 'ionic/ionic'; import {Geolocation} from 'ionic/ionic'; @IonicView({ template: ` Geolocation

Geolocation

Fetching location... {{location.coords.latitude}}, {{location.coords.longitude}}
Fetching location... {{trackLocation.coords.latitude}}, {{trackLocation.coords.longitude}}
` }) export class GeolocationPage { doGetLocation() { console.log('Getting location'); this.gettingLocation = true; Geolocation.getCurrentPosition().then((pos) => { this.gettingLocation = false; console.log('Got location', pos); this.location = pos; }, (err) => { this.gettingLocation = false; console.error('Unable to get location', err); }); } doTrackLocation() { this.gettingTrackLocation = true; Geolocation.watchPosition().source.subscribe((pos) => { this.gettingTrackLocation = false; console.log('Got location', pos); this.trackLocation = pos; }, (err) => { this.gettingTrackLocation = false; console.error('Unable to get location', pos); }); } }