ionic2 Geolocation Watching the position


For a more real time solution you can use watchPosition function in Geolocation that notifies whenever an error or a position change occurs. Unlike the getCurrentPosition the watchPosition returns an Observable

import {Geolocation} from 'ionic-native';
import template from './custom-component.html';

selector: 'custom-component',
template: template
export class CustomComponent {
constructor() {

    // get the geolocation through an observable
            maximumAge: 5000, // a maximum age of cache is 5 seconds
            timeout: 10000, // time out after 10 seconds
            enableHighAccuracy: true // high accuracy 
        }).subscribe((position) => {
            console.log('Time:' + position.timestamp);
                'Position:' + position.coords.latitude + ',' +
            console.log('Direction:' position.coords.heading);
            console.log('Speed:' position.coords.speed);