Error with geocode API in ionic

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

Anyone know what could be causing this error?

Error message says: results is null during execution.

I don’t understand how it can be null if I’m using it in the callback. The result is valid because the marker does end up on the map. I’m really confused

console.log(results) can help solve this confusion.
If it outputs a valid value while throwing that error, something else is amiss.

console.log(results) does give undefined once and an array for the rest of the markers. But sometimes, it doesn’t give any undefined and an array for all the markers

So when there is no undefined you don’t get any errors, right?

Then you will find out why this goes into the callback with undefined results. If this is ok behaviour (which sounds strange), you will probably have to handle it in your code and check for undefined.