看着这个位置

对于更实时的解决方案,你可以在 Geolocation 中使用 watchPosition 函数,该函数会在发生错误或位置更改时通知。与 getCurrentPosition 不同,watchPosition 返回一个 Observable

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

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

    // get the geolocation through an observable
        Geolocation.watchPosition(<GeolocationOptions>{
            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);
            console.log(
                'Position:' + position.coords.latitude + ',' +
                position.coords.longitude);
            console.log('Direction:' position.coords.heading);
            console.log('Speed:' position.coords.speed);

        });
}