我有购物中心的图片,我需要将其用作我正在制作的应用的地图。我有地图底部角落的GPS纬度/长度,我想出了从底部GPS坐标到地图图像顶部的距离。这些不是直线上下线性地图意味着我不能只绘制我的纬度和长度都很好和整洁。
我已经尝试过使用各种公式而且距离我很近,但是我无法绘制地图左上角和右上角的顶部纬度和长度。到目前为止,这就是我所拥有的:
double distanceFromLeftToRightGPS = bottomLeft.distanceTo(bottomRight);
double bearingleftToRight= bottomLeft.bearingTo(bottomRight);
double distmapFromLeftToRightImg = map.getWidth();
double distmapFromTopToBottomImg = map.getHeight();
double percentageValueOfTopToBottomImg = (distmapFromTopToBottomImg * 100)
/ distmapFromLeftToRightImg;
double distanceFromTopToBottomGPS = (percentageValueOfTopToBottomImg * 0.01)
* distanceFromLeftToRightGPS;
double bearingToTopFromBottom = -90;
double lat1 = Math.toRadians(bottomLeft.getLatitude());
double lon1 = Math.toRadians(bottomLeft.getLongitude());
double dist = (distanceFromTopToBottomGPS/1000f)/6371.0f;
double lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist)
+ Math.cos(lat1) * Math.sin(dist) * Math.cos(bearingToTopFromBottom));
double a = Math.atan2(Math.sin(bearingToTopFromBottom) * Math.sin(dist)
* Math.cos(lat1), Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2));
System.out.println("a = " + a);
double lon2 = lon1 + a;
lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI;
System.out.println("Latitude = " + Math.toDegrees(lat2) + "\nLongitude = "
+ Math.toDegrees(lon2));
这让我非常接近,但最终位置离开了它真正的位置。我也不确定应该用什么方法来查看地图底部的内容。如果其他人有一些关于如何使其工作的信息,这将是非常棒的。
答案 0 :(得分:1)
您需要使用纬度/经度坐标识别地图上的3个点。然后使用 Helmert 转换 在这里有一些关于“Helmert”转型的帖子。
答案 1 :(得分:0)
这两种方法我从其他帖子中提出了解决方案。如果您的地图的左上角和右下角有一个左上方的GPS坐标和一个右下方的GPS坐标,那么使用这两种方法可以找出在地图上绘制第三个GPS坐标的位置。这些将与您的左上和右下GPS坐标一样精确。然后我使用画布在位图上绘制第三个点。
public final static double OneEightyDeg = 180.0d;
public static double ImageSizeW, ImageSizeH ;
getSizesFromBitmap(ImageSizeW, ImageSizeH);
public double getCurrentPixelY(Location upperLeft, Location lowerRight, Location current) {
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceY = Math.cos(bearing * Math.PI / OneEightyDeg) * hypotenuse;
// "percentage to mark the position"
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceY = totalHypotenuse * Math.cos(upperLeft.bearingTo(lowerRight) * Math.PI / OneEightyDeg);
double currentPixelY = currentDistanceY / totalDistanceY * ImageSizeH;
return currentPixelY;
}
public double getCurrentPixelX(Location upperLeft, Location lowerRight, Location current) {
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceX = Math.sin(bearing * Math.PI / OneEightyDeg) * hypotenuse;
// "percentage to mark the position"
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceX = totalHypotenuse * Math.sin(upperLeft.bearingTo(lowerRight) * Math.PI / OneEightyDeg);
double currentPixelX = currentDistanceX / totalDistanceX * ImageSizeW;
return currentPixelX;
}