如何计算斜边和轴承

时间:2011-08-19 06:57:47

标签: android geolocation imagemap bearing hypotenuse

我通过此链接how-to-display-a-map-still-image-file-with-a-moving-current-location

从@DanS获得了以下代码
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
  • upperLeft:41.866514127810355,-87.6720142364502
  • lowerRight:41.83397145565242,-87.62824058532715
  • mapWidth:512 x 512 px

以下是位置,斜边(距离),方位(方位角)的在线计算器

我得到了结果:

  • hypotenuse = 2581
  • 方位= 135.21
  • currentDistanceX = -2562
  • currentPixelX = 311.9

想请你们:

  1. 确认我的计算结果是否正确。
  2. 关于如何计算currentPixelY(另一个点)?
  3. 顺便说一句,我打算用它来计算给定真实生活LatLng(当前)的位置,用我的静止图像贴图将静止图像的upperLeft和lowerRight角粘合到现实生活中LatLng。

    如果你想看到实际的&期望的输出,并希望轻松了解整个画面。请参阅此链接 - > How to mark the current location into a still image map

1 个答案:

答案 0 :(得分: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()