仮想トレッキングに参加しているユーザーの位置をマップに表示する Web アプリケーションを構築しようとしています。これらのトレッキングは長距離で、通常は高速道路で 500 km を超えます。私が知っている情報は、トレッキング ルート (ウェイ ポイントと一緒に開始、終了) と、開始点に関して彼が移動した距離です。
GMaps V3 では、Google マップで描かれた方向に沿って、開始点から x km のマーカーをプロットできます。
仮想トレッキングに参加しているユーザーの位置をマップに表示する Web アプリケーションを構築しようとしています。これらのトレッキングは長距離で、通常は高速道路で 500 km を超えます。私が知っている情報は、トレッキング ルート (ウェイ ポイントと一緒に開始、終了) と、開始点に関して彼が移動した距離です。
GMaps V3 では、Google マップで描かれた方向に沿って、開始点から x km のマーカーをプロットできます。
これを考え出した。この手法では、個々の緯度経度ステップを取得し、距離を段階的に計算します。個々のステップは、連続する 2 点間の直線近似を行うのに十分に近いです。最後のオーバーシュート点に対して逆トラバースが実行されます。
距離に関係なく、エラー率は 0.1% です。つまり、2000 km の距離は、マップ上で 2 km ずれます。
//Returns the Google LatLng object corresponding to distanceInKM for the given route.
//Params : directionResult : The google.maps.DirectionsResult obtained from DirectionService.route(request:DirectionsRequest, callback:function(DirectionsResult, DirectionsStatus))
//distanceInKM : The distance offset with respect to the starting point.
function getLatLngOnRoute(directionResult, distanceInKM) {
var lastPos=directionResult.routes[0].legs[0].steps[0].path[0]; var currPos;
var distance=0.0;
distanceInKM*=1000;
//Will not consider alternate routes.
for (var j=0; j<directionResult.routes[0].legs.length; j++) {
//There may be multiple legs, each corresponding to one way point. If there are no way points specified, there will be a single leg
for (var k=0; k<directionResult.routes[0].legs[j].steps.length; k++) {
//There will be multiple sub legs or steps
for (var l=0; l<directionResult.routes[0].legs[j].steps[k].path.length; l++) {
currPos=directionResult.routes[0].legs[j].steps[k].path[l];
//Calculate the distance between two lat lng sets.
distance+=google.maps.geometry.spherical.computeDistanceBetween(lastPos, currPos);
if (distance>distanceInKM) {
//If the exact point comes between two points, use distance to lat-lng conversion
var heading=google.maps.geometry.spherical.computeHeading(currPos, lastPos);
var l= google.maps.geometry.spherical.computeOffset(currPos, distance-distanceInKM, heading);
return l;
}
lastPos=currPos;
}
}
}
}
このトピックは私を正しい方向に導きました。