【问题标题】:How to compute hypotenuse and bearing如何计算斜边和方位
【发布时间】:2011-08-19 06:57:46
【问题描述】:

我从@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
  • currentDistanceX = -2562
  • currentPixelX = 311.9

想请大家:

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

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

如果您想查看实际和预期的输出并想轻松了解整个情况。请参考此链接->How to mark the current location into a still image map

【问题讨论】:

    标签: android geolocation imagemap bearing hypotenuse


    【解决方案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()。

    【讨论】:

    • 您介意帮助我了解如何显示图像地图并标记给定的当前坐标吗?你有示例 Eclipse 项目要分享吗?
    猜你喜欢
    • 1970-01-01
    • 2017-06-01
    • 1970-01-01
    • 2017-05-02
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多