I’m using the Google Maps Geocode API to read an address and place a marker on the map. This is how I’m using it :
this.geocoder = new google.maps.Geocoder();
this.geocoder.geocode({
'address': marker["address"]
}, (results,status) => {
var position = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng()); // error pointing to this line
this.personMarker = new google.maps.Marker({position: position, title: marker.name, markerInfo: marker, map : this.map , icon : marker.imageurl});
google.maps.event.addListener(this.personMarker, 'click', () => {
this.showCard = true;
this.org = marker.organization;
this.gig = marker.gig;
this.location = marker["address"];
this.image = marker.imageurl;
this.ngoData = marker;
this.ownerusername = marker.ownerusername;
});
});
I get this error : ‘Cannot read property ‘0’ of null’ pointing to the line I’ve shown with a comment in the code snippet. Interestingly, the marker does still show up on the map and on some occasions it doesn’t. Just don’t know what’s causing that error because I’m accessing the ‘results’ parameter only inside the callback