Geolocation - Cannot read property 'latitude' of undefined


#1

Hi,

I am using the cordova-plugin-geolocation.
I am successfully locating my android device but I am getting Cannot read property 'latitude' of undefined when launching the app in the browser.
Relevant part of my code:

this.watch = Geolocation.watchPosition({enableHighAccuracy: true })
.subscribe((position: Geoposition) => {

    this.interval = setInterval(function() {
      this.zone.run(() => {
        this.lat = position.coords.latitude;
        this.lng = position.coords.longitude;
      });
      console.log('lat: ' + this.lat + ', lon: ' + this.lng);
      LocalNotifications.schedule({
        id: 1,
        text: 'LocationTracker: '+ this.lat+', '+ this.lng,
        //icon: 'http://URL'
      });
    }.bind(this), 5000);
  });

Strangest thing is that it was perfectly working in the browser aswell last week.
I have installed the latest versions of node, cordova and ionic.

By the way, I have a button that is supposed to stop the location service:

stopTracking() {
this.watch.unsubscribe();
clearInterval(this.interval);
}

I also display the current latitude and longitude. Neither of these two lines stops the location tracking so my view’s lat and long keeps updating itself even after calling stopTracking().
Moreover, the interval is completely useless since the lat and long update every 0.5 seconds or so, while it should be every 5 seconds as specified.

Thanks


#2

So I came back this morning and Cannot read property 'latitude' of undefined is gone, geolocation works fine in the browser again.
I didn’t change anything since yesterday. Really strange.


#3

I am facing the same issue !!! it looks like native geolocation plugin is broken, anybody have any solution ?


#4

Still no solution …