如何使用 distanceTo() 方法计算传单中两个标记之间的距离?

问题描述

我需要你的帮助来使用 distanceTo() 方法计算两个标记之间的距离。 我试图在 Angular 中实现它,但在控制台中出现了以下错误:

代码如下:

display() {

    let from_select = $('#from_station option:selected').val();
    let to_select = $('#to_station option:selected').val();

    let filteredStations1 = this.stationsNames.filter( function(currentStation1:any) {
      return currentStation1.name == from_select;
    })

    let filteredStations2 = this.stationsNames.filter( function(currentStation2:any) {
      return currentStation2.name == to_select;
    })

    let from = JSON.parse(filteredStations1[0].loc_stringify);
    let to = JSON.parse(filteredStations2[0].loc_stringify);

    console.log(from.distanceTo(to));
  
  }

错误:

ERROR TypeError: from.distanceTo is not a function
    at AddEditTripComponent.display (main.js:1125)
    at AddEditTripComponent_Template_button_click_16_listener (main.js:1174)
    at executeListenerWithErrorHandling (vendor.js:58037)
    at wrapListenerIn_markDirtyAndPreventDefault (vendor.js:58072)
    at HTMLButtonElement.<anonymous> (vendor.js:76806)
    at ZoneDelegate.invokeTask (polyfills.js:9646)
    at Object.onInvokeTask (vendor.js:71332)
    at ZoneDelegate.invokeTask (polyfills.js:9645)
    at Zone.runTask (polyfills.js:9414)
    at ZoneTask.invokeTask [as invoke] (polyfills.js:9727)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)