Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何计算斜边和方位角_Android_Geolocation_Imagemap_Bearing_Hypotenuse - Fatal编程技术网

Android 如何计算斜边和方位角

Android 如何计算斜边和方位角,android,geolocation,imagemap,bearing,hypotenuse,Android,Geolocation,Imagemap,Bearing,Hypotenuse,我在这个链接上从@DanS获得了下面的代码 以下是数值: 当前:41.850033,-87.6500522999997 左上角:41.866514127810355,-87.6720142364502 右下角:41.83397145565242,-87.62824058532715 地图宽度:512 x 512像素 以下是位置、斜边(距离)、方位(方位)的在线计算器 我得到的结果是: 斜边=2581 轴承=135.21 currentDistanceX=-2562 currentP

我在这个链接上从@DanS获得了下面的代码

以下是数值:

  • 当前:41.850033,-87.6500522999997
  • 左上角:41.866514127810355,-87.6720142364502
  • 右下角:41.83397145565242,-87.62824058532715
  • 地图宽度:512 x 512像素
以下是位置、斜边(距离)、方位(方位)的在线计算器

我得到的结果是:

  • 斜边=2581
  • 轴承=135.21
  • currentDistanceX=-2562
  • currentPixelX=311.9
我想请你们:

  • 确认我的计算结果是否正确。
  • 关于如何计算当前像素(另一个点)?
  • 顺便说一句,我计划用它来计算一个给定的现实生活中的格子(当前)的位置,与我的静态图像贴图相比较,它将静态图像的左上角和右下角结合到现实生活中的格子中


    如果您希望看到实际和预期输出,并希望轻松理解整个画面。请参阅此链接->

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

    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项目要共享?
    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