简体   繁体   English

如何使用 JTS 计算 Java 中两个纬度/经度坐标之间的距离?

[英]How to calculate distance between two lat/long coordinates in Java using JTS?

I have two coordinates with latitude and longitude, and I want to calculated the distance between them in meters/miles.我有两个经纬度坐标,我想以米/英里为单位计算它们之间的距离。 Does the vividsolutions JTS library have the functionality to do this? vividsolutions JTS 库是否具有执行此操作的功能? If there is a function I can use please point me to it, thanks!如果有 function 我可以使用请指点我,谢谢!

JTS Will calc distance with the measurement unit the SRID is based on (so if you're using 4326 the number will literally be the diff in lat/lng). JTS 将使用 SRID 所基于的测量单位计算距离(因此,如果您使用 4326,则该数字实际上是 lat/lng 的差异)。 If you can convert to an SRID that is metric based, you can get a measurement in meters using distance, or distance3d (if your objects have a 3rd dimension for elevation).如果您可以转换为基于公制的 SRID,则可以使用距离或 distance3d(如果您的对象具有高程的第三维)以米为单位进行测量。 Then convert that to other units if you need to.如果需要,然后将其转换为其他单位。

You can also do the math, but isn't a basic conversion - it takes into account the radius of the earth, and other geometric issues (things the spatial reference will do for you).您也可以进行数学计算,但不是基本转换 - 它考虑了地球的半径和其他几何问题(空间参考将为您做的事情)。 If prefer that way search for something like "convert lat long to meters" and something will pop up.如果更喜欢这种方式,请搜索“将经纬度转换为米”之类的内容,然后会弹出一些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM