我在弄清楚我的错误在哪里时遇到了一些问题。我得到以下信息:
具有图像和其左上角和右下角顶点的相应 GPS 坐标。例如:
topLeft.longitude = 8.235128;
topLeft.latitude = 49.632383;
bottomRight.longitude = 8.240547;
bottomRight.latitude = 49.629808;
现在 a 有一个位于该地图中的点:
p.longitude = 8.238567;
p.latitude = 49.630664;
我以横向全屏(1024 * 748)绘制我的图像。
现在我想计算我的点的确切像素位置(x,y)。
为此,我试图从这里使用大圆距离方法:Link。
CGFloat DegreesToRadians(CGFloat degrees)
{
return degrees * M_PI / 180;
};
- (float) calculateDistanceP1:(CLLocationCoordinate2D)p1 andP2:(CLLocationCoordinate2D)p2 {
double circumference = 40000.0; // Erdumfang in km am Äquator
double distance = 0.0;
double latitude1Rad = DegreesToRadians(p1.latitude);
double longitude1Rad = DegreesToRadians(p1.longitude);
double latititude2Rad = DegreesToRadians(p2.latitude);
double longitude2Rad = DegreesToRadians(p2.longitude);
double logitudeDiff = fabs(longitude1Rad - longitude2Rad);
if (logitudeDiff > M_PI)
{
logitudeDiff = 2.0 * M_PI - logitudeDiff;
}
double angleCalculation =
acos(sin(latititude2Rad) * sin(latitude1Rad) + cos(latititude2Rad) * cos(latitude1Rad) * cos(logitudeDiff));
distance = circumference * angleCalculation / (2.0 * M_PI);
NSLog(@"%f",distance);
return distance;
}
这是我获取像素位置的代码:
- (CGPoint) calculatePoint:(CLLocationCoordinate2D)point {
float x_coord;
float y_coord;
CLLocationCoordinate2D x1;
CLLocationCoordinate2D x2;
x1.longitude = p.longitude;
x1.latitude = topLeft.latitude;
x2.longitude = p.longitude;
x2.latitude = bottomRight.latitude;
CLLocationCoordinate2D y1;
CLLocationCoordinate2D y2;
y1.longitude = topLeft.longitude;
y1.latitude = p.latitude;
y2.longitude = bottomRight.longitude;
y2.latitude = p.latitude;
float distanceX = [self calculateDistanceP1:x1 andP2:x2];
float distanceY = [self calculateDistanceP1:y1 andP2:y2];
float distancePX = [self calculateDistanceP1:x1 andP2:p];
float distancePY = [self calculateDistanceP1:y1 andP2:p];
x_coord = fabs(distancePX * (1024 / distanceX))-1;
y_coord = fabs(distancePY * (748 / distanceY))-1;
return CGPointMake(x_coord,y_coord);
}
x1 和 x2 是 p 的经度和纬度为 topLeft 和 bottomRight 的点。y1 和 y2 是 p 的纬度上的点,经度为 topLeft 和 bottomRight。
所以我得到了p经度上左右之间的距离和p纬度上上下之间的距离。(需要计算像素位置)
现在我计算 x1 和 p 之间的距离(我在 x_0 和 x_p 之间的距离),然后我计算 y1 和 p 之间的距离(y_0 和 y_p 之间的距离)
最后但并非最不重要的一点是计算并返回像素位置。
结果是,我的观点是红色而不是蓝色:
也许您发现任何错误或对提高准确性有任何建议。