Reputation: 69
google.maps.event.addListener(Marker, 'click', (function(Marker) {
return function() {
this.storage.set('mylocation', this.Marker.getPosition());
}
})(Marker));
polyfills.js:3 Uncaught TypeError: Cannot read property 'set' of undefined
I'm getting this error when I try to set storage in Ionic 3 with the response from google maps marker dragend event.
Upvotes: 0
Views: 141
Reputation:
Cannot read property 'set' of undefined
This would mean that "storage" is undefined. If storage is undefined be sure to declare it in the constructor and import it correctly like here: Ionic Storage Docs
import { Storage } from '@ionic/storage';
export class MyApp {
constructor(private storage: Storage) { }
...
// set a key/value
this.storage.set('name', 'Max');
// Or to get a key/value pair
this.storage.get('age').then((val) => {
console.log('Your age is', val);
});
}
If the Error gets thrown because this.Marker.getPosition()
is null you could try the solution from Ahkil J:
google.maps.event.addListener(Marker, 'click', (function(Marker) {
return function() {
this.LastLat = Marker.position.lat();
this.LastLng = Marker.position.lng();
this.storage.set('mylocation', this.LastLat + this.LastLng);
}
})(Marker));
Upvotes: 1
Reputation: 69
For those who are having this error, solve like the below. I found it from here Ionic Framework dragend solution
google.maps.event.addListener(marker, 'dragend', () =>{
this.LastLat= marker.position.lat();
this.LastLng= marker.position.lng();
this.storage.set('mylocation', this.LastLat);
});
Upvotes: 0