HI
I am using ionic 5 with capacitor 3
I need to watch the GPS position. The Geolocation.watchPosition method works fine and returns the user’s positions.
the problem is when I call the method clearWatch. it returns error:
main.js:1 ERROR Error: Uncaught (in promise): Error: Watch call id must be provided
Error: Watch call id must be provided
at Object.cap.fromNative (137:429)
the following is my code
import { ClearWatchOptions, Geolocation } from '@capacitor/geolocation';
import { Component, OnInit, NgZone } from '@angular/core';
export class JournyPage implements OnInit {
public lat: any;
public lng: any;
public id: any;
watchTrack() {
this.id = Geolocation.watchPosition({}, (position, err) => {
this.ngZone.run(() => {
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
console.log('location changed===> ','lat: '+this.lat+' lng:'+this.lng);
});
});
stopTrack() {
console.log('this.wait=',this.id);
Geolocation.clearWatch({ id: this.id });
}
}
this is the log:
result Geolocation.watchPosition (#13919546)
1124.js:1 location changed===> lat: 29.3296222 lng:48.0201577
1124.js:1 this.wait= e {__zone_symbol__state: true, __zone_symbol__value: ‘13919546’}
137:231 native Geolocation.clearWatch (#13919547)
137:205 result Geolocation.clearWatch (#13919547)
main.js:1 ERROR Error: Uncaught (in promise): Error: Watch call id must be provided
Error: Watch call id must be provided
at Object.cap.fromNative (137:429)
please help. How can I stop watching GPS location