Currently, I have integrated HTML 5 geolocation into an Angular component:
...
export class AngularComponent {
...
constructor(private db: DatabaseService) {}
// this function is linked to an HTML button
logCoords(message, action) {
navigator.geolocation.getCurrentPosition(this.success, this.error, this.options);
}
success(pos) {
function time() {
...
}
var crd = pos.coords;
var lat = crd.latitude
var long = crd.longitude
let newCoordinates = {'lat': lat, 'long':long, 'time': time}
this.db.addLocation(newCoordinates)
}
...
}
...
I am trying to save the result of the getCurrentPosition Method in indexed db using an Angular service, but unfortunately the component class properties are inaccessible (this.db is null).
Why can't I access this.db within the success function and what possible solutions could help me overcome this issue?