Hi,
I’m having an issue with the variables in my app.component.ts appearing as ERROR [object object], while when I just do a console.log - everything seems fine.
The variable userLocation is correctly created in my provider…
I need help, is this an issue with watchPosition() or am I doing something wrong?
Here’s the code:
let watch = this.geolocation.watchPosition();
watch.subscribe((data) => {
// data can be a set of coordinates, or an error (if an error occurred).
this.locationProvider.userLocation.lat = data.coords.latitude;
this.locationProvider.userLocation.lng = data.coords.longitude;
console.log(data.coords.latitude, ' ', data.coords.longitude);
});
This is the error I’m getting in console when trying to build it:
VM1745 ion-dev.js:156 ERROR TypeError: Cannot set property 'lat' of undefined at SafeSubscriber._next (VM49 main.js:686) at SafeSubscriber.__tryOrUnsub (VM48 vendor.js:35724) at SafeSubscriber.next (VM48 vendor.js:35671) at Subscriber._next (VM48 vendor.js:35611) at Subscriber.next (VM48 vendor.js:35575) at t.invoke (VM47 polyfills.js:3) at Object.onInvoke (VM48 vendor.js:5134) at t.invoke (VM47 polyfills.js:3) at r.runGuarded (VM47 polyfills.js:3) at VM47 polyfills.js:3