我通过此链接从 @DanS 获得了以下代码如何显示带有移动当前位置的地图静止图像文件 https://stackoverflow.com/questions/7062115/android-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 像素
这是位置、斜边(距离)、方位角(方位角)的在线计算器
- 将 LatLng 转换为位置格式(例如 41° 51′ 59.45″ N 87° 40′ 19.25″ W) http://tools.freeside.sk/geolocator/geolocator.html
- 计算距给定位置的距离和方位角 http://transition.fcc.gov/mb/audio/bickel/distance.html
我得到的结果是:
- 斜边 = 2581
- 轴承 = 135.21
- 当前距离X = -2562
- 当前像素X = 311.9
想请教一下各位:
- 确认我的计算结果是否正确。
- 关于如何计算 currentPixelY (另一点)?
顺便说一句,我计划用它来计算给定现实生活中的 LatLng(当前)的位置,并与我的静态图像贴图进行比较,该静态图像贴图将静态图像的左上角和右下角粘合到现实生活中的 LatLng 中。
如果您想查看实际和预期的输出并希望轻松了解整个情况。请参考此链接->如何将当前位置标记到静态图像地图中 https://stackoverflow.com/questions/7072400/android-how-to-mark-the-current-location-into-a-map-still-image-source-code
这是我正在使用的实际代码,而不是之前发布的伪代码:
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()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)