Google Map Api Uncaught TypeError: Unable to read property '0' from null

advertisements

I am face the problem Uncaught TypeError: Cannot read property '0' of null on converting the address to latitude and longitude this the my code

The code is

function convertAddress( address, callback, item ) {
    geocoder.geocode( {
        'address' : address
    }, function(results, status) {
        if ( status == google.maps.GeocoderStatus.OK ) {
            callback( results[0].geometry.location );
        }

        cords = [ results[0].geometry.location.pb, results[0].geometry.location.qb ];

        $.post( jobifySettings.ajaxurl, { action : 'jobify_cache_cords', cords : cords, job : item.job } );
    });
}


  1. don't use undocumented properties (location.pb, location.qb)
  2. don't put code that depends on a successful result outside of the check for success

    function convertAddress( address, callback, item ) {
      geocoder.geocode( {
        'address' : address
      }, function(results, status) {
        if ( status == google.maps.GeocoderStatus.OK ) {
          callback( results[0].geometry.location );
          cords = [ results[0].geometry.location.lat(), results[0].geometry.location.lng() ];
          $.post( jobifySettings.ajaxurl, { action : 'jobify_cache_cords', cords : cords, job : item.job } );
        } else alert("Geocode failed, status: "+status);
      });
    }