0

我从@DanS 在此链接how-to-display-a-map-still-image-file-with-a-moving-current-location获得了以下代码

onCurrentPosition(Location current){
    double hypotenuse = upperLeft.distanceTo(current);
    double bearing = upperLeft.bearingTo(current);
    double currentDistanceX = Math.cos(bearing) * hypotenuse;
    //                     "percentage to mark the position"
    double currentPixelX = (currentDistanceX / upperLeft.distanceTo(lowerRight) * Math.cos(upperLeft.bearingTo(lowerRight))) * mapWidth;

    moveIndicatorX(currentPixelX);
}

以下是值:

  • 当前:41.850033,-87.65005229999997
  • 左上:41.866514127810355,-87.6720142364502
  • 右下:41.83397145565242,-87.62824058532715
  • 地图宽度:512 x 512 像素

这是位置、斜边(距离)、方位角(方位角)的在线计算器

我得到了以下结果:

  • 斜边 = 2581
  • 轴承 = 135.21
  • 当前距离X = -2562
  • 当前像素X = 311.9

想请教各位:

  1. 确认我的计算结果是否正确。
  2. 关于如何计算 currentPixelY(另一点)?

顺便说一句,我计划使用它来计算给定现实生活 LatLng(当前)的位置,并与我的静止图像映射将静止图像的左上角和右下角结合到现实生活中的 LatLng 中。

如果您想查看实际和预期的输出并想轻松理解整个画面。请参考此链接 ->如何将当前位置标记为静止图像地图

4

1 回答 1

1

这是我正在使用的实际代码,而不是之前发布的伪代码:

Location upperLeft = new Location("");
upperLeft.setLatitude(41.866514127810355);
upperLeft.setLongitude(-87.6720142364502);
Location lowerRight = new Location("");
lowerRight.setLatitude(41.83397145565242);
lowerRight.setLongitude(-87.62824058532715);
Location current = new Location("");
current.setLatitude(41.850033);
current.setLongitude(-87.65005229999997);
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceX = Math.cos(bearing * Math.PI / 180.0) * hypotenuse;
//                     "percentage to mark the position"
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceX = totalHypotenuse * Math.cos(upperLeft.bearingTo(lowerRight) * Math.PI / 180.0);
double currentPixelX = currentDistanceX / totalDistanceX * 512;

System.out.println(currentPixelX); // 259.3345493341548

你计算出来的答案看起来有点不对劲。要计算 Y 更改,请复制所有 X 标记的计算和变量以使用Math.sin(),而不是Math.cos().

于 2011-08-19T17:05:57.623 回答