Google Map Api Uncaught TypeError:无法读取null的属性'0' [英] Google Map Api Uncaught TypeError: Cannot read property '0' of null

查看:202
本文介绍了Google Map Api Uncaught TypeError:无法读取null的属性'0'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临的问题Uncaught TypeError:无法读取属性'0'null转换为经纬度这是我的代码

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

代码是

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. 不要使用未记录的属性(location.pb,location.qb)
  2. 不要在成功检查之外放置依赖于成功结果的代码

  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);
  });
}


这篇关于Google Map Api Uncaught TypeError:无法读取null的属性'0'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆