angular - TypeError:无法读取未定义的属性“几何” - Angular
问题描述
每当我将数据发送到对 Angular Google Maps 的用户地址进行地理编码的方法时,我都会收到此错误:
Uncaught TypeError: Cannot read property 'geometry' of undefined
我试图查看源包以查看是否geometry
已定义并且似乎已定义,但它仍然无法正常工作!
解决方案
在你的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 密钥,所以您的请求将始终被拒绝。
推荐阅读
- ios - 如何创建支持手写文本和在同一页面上键入文本的绘图视图,类似于 IOS Notes App
- html - 滚动棒/跳转第二个中途网站
- react-native - google-play-service 更新后无法在 react-native 中构建 android 应用程序
- python - 如何根据 python 中的条件从现有列表创建自定义列表?
- magento2 - $attribute->getFrontendInput() 方法的行为是什么?
- ios - 如何使用日期格式化程序从 00:00:00(到 23:00:00)获取 1 - 12 am/pm 格式?
- mysql - 如果删除了所有子实体,则删除父实体
- xamarin - 位置缓存是如何工作的?
- system-verilog - systemverilog中fork块内的fork块和fork块内的fork块有什么区别?
- java - 在表中插值