【问题标题】:TypeError: Cannot read property 'geometry' of undefined - AngularTypeError:无法读取未定义的属性“几何” - Angular
【发布时间】:2019-06-28 12:39:03
【问题描述】:

每当我将数据发送到对 Angular Google 地图的用户地址进行地理编码的方法时,我都会收到以下错误:

Uncaught TypeError: Cannot read property 'geometry' of undefined


我的代码:https://stackblitz.com/edit/angular-gyvwjh


我已尝试查看源包以查看是否定义了geometry,并且似乎已定义,但它仍然无法正常工作!

【问题讨论】:

    标签: angular google-maps google-geocoder angular-google-maps


    【解决方案1】:

    在您的app.component 中,当您调用getAddress() 时,您有此检查。

    if (google.maps.GeocoderStatus.OK) { ... }
    

    这并不符合您的想法。这个测试总是正确的。因此,您继续拨打result[0].geometry,但没有任何结果。这就是为什么你有Cannot read property 'geometry' of undefined

    为此更改此测试。

    if (status === google.maps.GeocoderStatus.OK) { ... }
    

    顺便说一句,这将系统地执行警报,因为您没有设置 google api 密钥,所以您的请求将始终被拒绝。

    【讨论】:

    • 非常感谢!我有这个错误 12 天,以及其他所有这些错误。
    猜你喜欢
    • 2014-11-29
    • 2018-10-29
    • 2021-07-21
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多