Angular 为什么';计算两个地方之间的距离是否有效?

Angular 为什么';计算两个地方之间的距离是否有效?,angular,google-maps,Angular,Google Maps,我在angular中使用谷歌地图。我需要计算一个原点到多个其他目的地之间的距离,但该函数会返回相同的答案。 我能做什么 CalculateInstanceBy(地址存储:字符串) {let res; this.request.destination=this.tempArrToSaveAddresses[this.mone];this.mone=this.mone+1; 返回新承诺((解决,拒绝)=>{ 尝试 {this.counter=this.mone; this.directionsSer

我在angular中使用谷歌地图。我需要计算一个原点到多个其他目的地之间的距离,但该函数会返回相同的答案。 我能做什么

CalculateInstanceBy(地址存储:字符串) {let res; this.request.destination=this.tempArrToSaveAddresses[this.mone];this.mone=this.mone+1; 返回新承诺((解决,拒绝)=>{ 尝试 {this.counter=this.mone; this.directionsService.route(this.request,(response,status)=>{this.request.destination=this.tempArrToSaveAddresses[this.mone this.counter];this.counter=this.counter-1; if(status==google.maps.DirectionsStatus.OK){if(this.request.travelMode==google.maps.DirectionsTravelMode.WALKING) {res=response.routes[0]。legs[0]。duration.value;console.log(this.request.destination);} 其他的 if(this.request.travelMode==google.maps.DirectionsTravelMode.DRIVING) res=response.routes[0]。legs[0]。distance.text; console.log(“步行距离”,this.response.routes[0]。legs[0]。duration.value);console.log(“公里距离”,this.response.routes[0]。legs[0]。distance.text);console.log(res); 解析(res);} else{console.log(“oops”); res=0;resolve(res);}}catch(error){console.log(“catch”);resolve(0);}}}


tempArrToSaveAddresses:string[]=[];
lengthArr=0;
FindThreeMinPathPerProduct(product1:MinimumPath)
{
让productStores=this.listStoresPerProduct.find(sfp=>sfp.Product.productName==product1.Product.productName);
如果(!productStores){
返回
}
for(让index=0;index{
如果(res=product1.min1&&res {
//拒绝
})
}
}

您好,欢迎使用SO,请正确格式化您的代码。我不会成功。
tempArrToSaveAddresses:string[]=[];
 lengthArr=0;
  FindThreeMinPathPerProduct(product1:MinimumPath)
 {

  let productStores = this.listStoresPerProduct.find(sfp => sfp.Product.productName === product1.product.productName);
  if(!productStores) {
    return
  }

       for (let index = 0; index < productStores.Stores.length; index++) 
       {
        this.tempArrToSaveAddresses.push(productStores.Stores[index].addressStore);
        this.lengthArr=this.lengthArr+1;

        this.CalculateDistanceBy(productStores.Stores[index].addressStore)
        .then((res: number) => {

          if( res <  product1.min1  && res!=0)
          {
           product1.min1= res;
           product1.store1=productStores.Stores[index];
           debugger
         }
          else//|| res <  product1.min2
              if( res>=product1.min1 &&  res <  product1.min2  && res!=0 )
              {
               product1.min2= res;
               product1.store2=productStores.Stores[index];
               debugger
              }

              else
                  if( res< product1.min3  && res!=0)
                  {
                   product1.min3= res;
                   product1.store3=productStores.Stores[index];
                   debugger
                  }           
        }, () => {
          // reject
        })


      }


}