【发布时间】:2011-10-06 15:41:50
【问题描述】:
对于我的应用程序,我必须在谷歌地图上找到一个点的位置,只知道它位于其他 2 个点之间以及捕获坐标的时间(以毫秒为单位)。
在我的代码中,假设 A 和 B 作为给定点,X 作为要查找的点,我:
计算 A 和 B 之间的距离
根据时间,我发现了从 A 到 B 的速度(以微度/毫秒为单位)
我找到了A点和X点的距离(使用时间和速度)
使用相似三角形的规则,我从点A计算点X的经纬度
此工作流程会在地图上显示错误,因此 X 标记通常不在 A 和 B 标记之间的线上。
我怎样才能让它更好地工作?是不是地球的球度有问题?
谢谢大家。
代码如下:
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
int c1 = bx-ax;
int c2 = by-ay;
double hyp = Math.sqrt(Math.pow(c1, 2) + Math.pow(c2, 2));
double vel = hyp / (bt-at);
double pos = vel*(xt - at);
int posx = (int)((pos*c1)/hyp);
int posy = (int)((pos*c2)/hyp);
x.setLatitude(ax+posx); //set the latitude of X
x.setLongitude(ay+posy); // set the longitude of X
【问题讨论】:
标签: java android maps latitude-longitude