鉴于移动设备在短时间内的实时位置数据,如何在这条路上进一步获得一对纬度/长对,比如2英里,甚至更好,5分钟的驾驶?
我发现我可以使用Google的Roads API来捕捉一条长/长对https://developers.google.com/maps/documentation/roads/snap的道路,但这只会让我分道扬..
这将在Android应用中。
答案 0 :(得分:6)
如果路线表示为List<LatLng>
,则此函数计算路线上的点,该点来自该路线distance
的{{1}}米{(使用Google Maps API Utility Library}做一些计算):
origin
以下是一些测试:
private LatLng extrapolate(List<LatLng> path, LatLng origin, float distance) {
LatLng extrapolated = null;
if (!PolyUtil.isLocationOnPath(origin, path, false, 1)) { // If the location is not on path non geodesic, 1 meter tolerance
return null;
}
float accDistance = 0f;
boolean foundStart = false;
List<LatLng> segment = new ArrayList<>();
for (int i = 0; i < path.size() - 1; i++) {
LatLng segmentStart = path.get(i);
LatLng segmentEnd = path.get(i + 1);
segment.clear();
segment.add(segmentStart);
segment.add(segmentEnd);
double currentDistance = 0d;
if (!foundStart) {
if (PolyUtil.isLocationOnPath(origin, segment, false, 1)) {
foundStart = true;
currentDistance = SphericalUtil.computeDistanceBetween(origin, segmentEnd);
if (currentDistance > distance) {
double heading = SphericalUtil.computeHeading(origin, segmentEnd);
extrapolated = SphericalUtil.computeOffset(origin, distance - accDistance, heading);
break;
}
}
} else {
currentDistance = SphericalUtil.computeDistanceBetween(segmentStart, segmentEnd);
if (currentDistance + accDistance > distance) {
double heading = SphericalUtil.computeHeading(segmentStart, segmentEnd);
extrapolated = SphericalUtil.computeOffset(segmentStart, distance - accDistance, heading);
break;
}
}
accDistance += currentDistance;
}
return extrapolated;
}