Hi!
I have some code that independently works, but when I put it together I get “Undefined” error at "this"
It surly have something to to with my lack of understanding JS this, that.
I get it to work in Ionic 1, but not in Ionic 2.
I would we very thankful for guidance. Here is the essential parts of the code:
platform.ready().then(() => {
this.loadMap();
});
//---------Loading map ----------
loadMap(){
Geolocation.getCurrentPosition().then((position) => {
this.map = new GoogleMap(‘map’, {
‘backgroundColor’: ‘white’,
‘controls’:…
…
…
}
this.map.on(GoogleMapsEvent.MAP_READY).subscribe(() => {
this.getMarkers();
},
(err) => {
console.log(err);
});
});
}
//-----Get markers from Geofire/Firebase
getMarkers(){
…
…
var geoQuery = geoFire.query({
center: [lat,lon],
radius: 3000
});
…
var onKeyEnteredRegistration = geoQuery.on(“key_entered”, function(key, location) {
this.addmarker(location)
});
}
}
//-------Adding marker to map
addmarker(location){
let markerOptions: GoogleMapsMarkerOptions = {position: location, title: ‘Some title’ };
this.map.addMarker(markerOptions) <------------------------ This gives error
.then((marker: GoogleMapsMarker) => {
marker.showInfoWindow();
});
}