I am using HTML 5 geolocation inside an Angular component:
...
export class AngularComponent {
...
constructor(private db: DatabaseService) {}
// this function is assigned 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 want to store the result of the getCurrentPosition Method inside indexed db using an Angular service but I am unable to access any properties of the component class (this.db is null).
Why I am unable to access this.db inside the success function and how I might be able to work around this?