0

我想看看这是否

 Math.sqrt(
           Math.pow((position.coords.latitude -45),2) + 
           Math.pow((position.coords.longitude-75),2)
          )*79; 

匹配这个:

 Distance to store (km) = Square Root (
                                       (Current Latitude – 45)^2 + 
                                       (Current Longitude ‐75)^2
                                      ) *79

现在我得到了 11,XXX KM,这已经很多了,但我没有看到任何错误。

我也试过这样做:

var x = Math.pow((position.coords.latitude-45),2);
    var y = Math.pow((position.coords.longitude-75),2);
    var z = Math.sqrt(x+y);
    var zz = z*79;

但它给了我同样的答案。

4

1 回答 1

0

此公式适用于到纬度 45 和经度 75 的短距离。

由于您不在哈萨克斯坦,您想要的是到(45,-75)的距离,即

Math.sqrt(Math.pow((lat-45),2)+Math.pow((lon+75),2))*79; 
                                            ^

请注意,它仅与您的坐标精确一样精确,并且对于更大的距离,您应该获取更好的公式

于 2013-03-27T10:36:57.003 回答