【问题标题】:Map GPS Coordinates to an Image and draw some GPS Points on it将 GPS 坐标映射到图像并在其上绘制一些 GPS 点
【发布时间】:2011-03-26 15:36:46
【问题描述】:

我在弄清楚我的错误在哪里时遇到了一些问题。我得到了以下信息:

拥有一张图像及其左上角和右下角顶点的相应 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)。

为此,我尝试从这里使用大圆距离方法: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 之间的距离)

最后但并非最不重要的一点是计算并返回像素位置。

结果是,我的观点是红色而不是蓝色:

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

【问题讨论】:

标签: objective-c ipad map gps great-circle


【解决方案1】:

也许我不明白你的问题,但你不应该使用MKMapViewConverting Map Coordinates 方法吗?

【讨论】:

    【解决方案2】:

    this image

    我使用了你的坐标,并且简单地做了以下事情:

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

    红点标记了这一点。对于这么小的距离,您实际上不需要使用大圆圈,并且您的舍入误差会使事情变得更加不准确

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 2013-01-09
      • 1970-01-01
      • 2012-10-19
      • 1970-01-01
      • 2012-09-21
      相关资源
      最近更新 更多