我是latitude-longitude的新手,我尝试用给定的值计算两点之间的距离。我想要几英里的距离。我在Anylogic网站上找到了一个方法,如下所示
default double getDistance(double startLat,
double startLon,
double endLat,
double endLon)按两个指定点之间的路由计算距离。返回:两个指定点之间的距离,以米为单位。
但是,当我用lat-long运行两组点时,
Point 1:
latitude:41.40174, longitude: -72.0201
Point 2:
latitude:45.332, longitude:-73.2215这给了我一段距离的4.1098062654025815米,在任何逻辑上;哪一个是wrong.Could,请你帮助我洞察我可能做错了什么?谢谢
发布于 2019-11-27 11:17:03
出什么事了
您目前正在使用来自实用程序的标准距离函数,它使用输入作为笛卡尔坐标,而不是作为地理纬度和逻辑:
public static final double getDistance(double x1,double y1,double x2,double y2)
Returns the distance between two given points (x1, y1) and (x2, y2)
Parameters:x1 - the x coordinate of the first pointy1 - the y coordinate of the first pointx2 - the x coordinate of the second pointy2 - the y coordinate of the second point
Returns:the distance between points如何修复它
为了计算纬度和经度的地理距离,您必须访问ShapeGISMap对象附带的函数。
double getDistanceByRoute(double latFrom, double lonFrom, double latTo, double lonTo)
Calculates length of route from one point to another.double getDistance(double latFrom, double lonFrom, double latTo, double lonTo)
Returns distance, in meters, between 2 given points您可以通过从SpaceMarkup调色板(这里的实例名为map)添加一个GIS来访问它们,并引用它:
map.getDistanceByRoute(41.40174,-72.0201,45.332,-73.2215);附加提示
通过使用(键入函数名的第一部分,然后是CTRL +空格栏)并查看JavaDoc,始终可以检查上下文中是否确实使用了正确的函数:

https://stackoverflow.com/questions/59055106
复制相似问题