如何在经度和纬度两个点之间前进X距离(米)?

问题描述 投票:0回答:1

我正在用Java在不同的停靠点处模拟一条折线,我在两点之间的距离以米为单位,问题是,我必须以每秒1至3米的速度从A点到B点,并且需要每隔15分钟或多或少获取当前坐标,该怎么办?

两点之间的方式是直线,并且所有这些都是模拟的,不会在地图上或其他东西中发生,我只需要每X次打印此信息,有什么帮助吗?

示例:

我有坐标:

LAT: 51.504870000000004 LNG: -0.21533000000000002

而且我必须以这种速度去:

LAT: 51.50475 LNG: -0.21571

所以,我必须模拟我从A到B在3米处走动,并且我需要知道我在这两个点之间移动时的位置(经/纬度)

java maps latitude-longitude
1个回答
0
投票

我不清楚这个问题,但是如果您想在给定距离后做点什么,可以使用此方法

LatLng startPoint=new LatLng(51.504870000000004,-0.21533000000000002);
LatLng endPoin=new LatLng(51.50475,-0.21571);
Location loc1 = new Location("");
loc1.setLatitude(startPoint.latitude);
loc1.setLongitude(startPoint.longitude);
Location loc2 = new Location("");
loc2.setLatitude(endPoint.latitude);
loc2.setLongitude(endPoint.longitude);
float distance = loc1.distanceTo(loc2);
//instead of if you can use for loop
if (distance <= 100) {
//do something, like get the coordinates
} else {
 //do something
}
© www.soinside.com 2019 - 2024. All rights reserved.