angular - 无效值错误 : in property origin: not a string; and not a LatLng or LatLngLiteral: not an Object; and not an Object

标签 angular google-maps

我正在使用 Angular 谷歌地图来设置当前位置和 agm-direction 来设置方向。下面是代码,我遇到了上述错误。

最佳答案

这可能是因为当您调用 getDirections() 时,您的组件的 latlng 没有被填充。 getUserLocation() 不会同步产生位置坐标。您可以通过在浏览器控制台中粘贴来检查 getUserLocation() 下的代码。你会发现给你职位需要时间。如果您在给出结果所花费的时间之间调用 getDirections().. 您将收到上述错误。

我像这样制作了 getDirections():

async getDirection() {
    if (typeof this.lat == "undefined" || typeof this.lng == "undefined" || typeof this.zoom == "undefined") {
      await this.getUserLocation();
    }
    // code below will not be executed until getUserLocation() is complete
    this.origin = { lat: this.lat, lng: this.lng };
    this.destination = { lat: 24.799524, lng: 120.975017 };
} 

您的 getUserLocation() 将最多被调用两次..

关于angular - 无效值错误 : in property origin: not a string; and not a LatLng or LatLngLiteral: not an Object; and not an Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52260355/

相关文章:

android - map 未进入模拟器 android api v2

java - 使用 Java 使用 Google Map 下载 map 图像

angular - 错误 NG6002 : Appears in the NgModule. 导入 <module>,但无法解析为 NgModule 类

dependency-injection - angular2 中服务的生命周期方法

javascript - Angular 4 : can't redirect from inside a subscribe

javascript - 如何从地址获取纬度和经度并将其传递给 react 传单?

安卓自定义 map 源

Angular 9 和 Storybook : Add @angular/localize/init polyfill

javascript - Angular Date 管道,以及一个带有 Momentjs 的简单计时器

ios - 如何使用 Google API 固定用户的当前位置?