您可以通过以下步骤解决您的问题.
>计算A点和B点的距离(使用Haversine formula,这在这里足够好,或者更复杂的Vincenty formula).要使用
公式正确,Android的microdegrees,这就是getLatitude
和getLongitude返回,必须转换为弧度,
使用这样的公式:
double radians = Math.toRadians((double)microdegrees/1000000);
>从A点和B点计算轴承(方向)(使用公式
在同一页上).这与毕达哥拉斯公式不同,因为
地球是圆的,不是平的.
>然后你可以选择一个新的距离并计算给定的X点
A点和上一步中找到的轴承(参见同一页面上的“目标点给定距离和起点承载”或Vincenty’s
direct formula).
>使用以下公式将生成点的弧度转换为微度:
int microdegrees = (int)(Math.toDegrees(radians)*1000000);
总而言之,我们有以下功能,我将其置于公共领域:
public static int[] getIntermediatePoint(
int startLatMicroDeg,
int startLonMicroDeg,
int endLatMicroDeg,
int endLonMicroDeg,
double t // How much of the distance to use, from 0 through 1
){
// Convert microdegrees to radians
double alatRad=Math.toRadians((double)startLatMicroDeg/1000000);
double alonRad=Math.toRadians((double)startLonMicroDeg/1000000);
double blatRad=Math.toRadians((double)endLatMicroDeg/1000000);
double blonRad=Math.toRadians((double)endLonMicroDeg/1000000);
// Calculate distance in longitude
double dlon=blonRad-alonRad;
// Calculate common variables
double alatRadSin=Math.sin(alatRad);
double blatRadSin=Math.sin(blatRad);
double alatRadCos=Math.cos(alatRad);
double blatRadCos=Math.cos(blatRad);
double dlonCos=Math.cos(dlon);
// Find distance from A to B
double distance=Math.acos(alatRadSin*blatRadSin +
alatRadCos*blatRadCos *
dlonCos);
// Find bearing from A to B
double bearing=Math.atan2(
Math.sin(dlon) * blatRadCos,
alatRadCos*blatRadSin -
alatRadSin*blatRadCos*dlonCos);
// Find new point
double angularDistance=distance*t;
double angDistSin=Math.sin(angularDistance);
double angDistCos=Math.cos(angularDistance);
double xlatRad = Math.asin( alatRadSin*angDistCos +
alatRadCos*angDistSin*Math.cos(bearing) );
double xlonRad = alonRad + Math.atan2(
Math.sin(bearing)*angDistSin*alatRadCos,
angDistCos-alatRadSin*Math.sin(xlatRad));
// Convert radians to microdegrees
int xlat=(int)Math.round(Math.toDegrees(xlatRad)*1000000);
int xlon=(int)Math.round(Math.toDegrees(xlonRad)*1000000);
if(xlat>90000000)xlat=90000000;
if(xlat
while(xlon>180000000)xlon-=360000000;
while(xlon<=-180000000)xlon+=360000000;
return new int[]{xlat,xlon};
}
以下是它的使用方法:
int ax = oldPoint.getLatitude();
int ay = oldPoint.getLongitude();
int bx = currentPoint.getLatitude();
int by = currentPoint.getLongitude();
long at = oldPoint.getDataRilevamento(); //get time first point
long bt = currentPoint.getDataRilevamento(); // get time second point
long xt = x.getDate(); // time of point to find
// Find relative time from point A to point B
double t=(bt==at) ? 0 : ((double)(xt-at))/((double)(bt-at));
// Find new point given the start and end points and the relative time
int[] xpos=getIntermediatePoint(ax,ay,bx,by,t);
x.setLatitude(xpos[0]); //set the latitude of X
x.setLongitude(xpos[1]); // set the longitude of X