将GPS坐标映射到图像上并在其上绘制一些GPS点

3

我有一些问题,无法确定我的错误在哪里。我得到了以下内容:

有一张图片和其左上角和右下角顶点的GPS坐标。

topLeft.longitude = 8.235128;
topLeft.latitude = 49.632383;
bottomRight.longitude = 8.240547;
bottomRight.latitude = 49.629808;

现在我有一个点位于该地图上:
p.longitude = 8.238567;
p.latitude = 49.630664;

我在横向全屏幕(1024 * 748)中绘制了我的图像。

现在我想计算我的点的精确像素位置(x,y)。

为了做到这一点,我正在尝试使用这里的大圆距离方法:链接

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之间的距离)

最后计算并返回像素位置。

结果是,我的点位于红色位置而非蓝色位置:

Screenshot

也许您会发现任何错误或有任何建议来提高准确性。


我有同样的问题,你能给我一个好的公式吗? - Safouane Azzabi
2个回答

0

查看此图像

我使用了您的坐标,并简单地执行了以下操作:

x_coord = 1024 * (p.longitude - topLeft.longitude)/(bottomRight.longitude - topLeft.longitude);
y_coord =  748 - (748 * (p.latitude - bottomRight.latitude)/(topLeft.latitude - bottomRight.latitude));

这个红点标记了这个点。对于这样小的距离,您不需要使用大圆线,因为舍入误差会使事情变得更加不准确。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接