iOS CoreLocation在图像顶部绘制用户位置

时间:2011-08-14 17:31:21

标签: iphone objective-c ios4 core-location

我正在尝试创建类似于http://navigationapps.com/wp-content/uploads/2010/10/point-inside-2.png的建筑物导航应用程序。我打算将建筑平面图图像显示为UIImageView,并使用CoreLocation获取针指针的经度和纬度坐标。下一步 - 我也坚持下去,我如何在图像上绘制点? - 我已经能够检索用户的纬度和批次坐标..

1 个答案:

答案 0 :(得分:3)

嗯,首先是UIImageView为pin指针显示某种图标,然后是一个将lat / long坐标转换为图像位置的函数。

假设您的建筑平面图图像与顶部的北方对齐,

- (CGPoint)plotPointOfLocation:(CLLocationCoordinate2D)location {
    CLLocationCoordinate2D topLeftCoordinate = CLLocationCoordinate2DMake(/* the lat/long of the top-left of the plan image */);
    CLLocationCoordinate2D bottomRightCoordinate = CLLocationCoordinate2DMake(/* the lat/long of the bottom-right of the plan image */);
    CGSize planImageSize = CGSizeMake(/* the size of the plan image, as drawn on the screen, in pixels */);

    CLLocationDegrees latSpan = bottomRightCoordinate.latitude - topLeftCoordinate.latitude;
    CLLocationDegrees longSpan = bottomRightCoordinate.longitude - topLeftCoordinate.longitude;

    CLLocationCoordinate2D offsetLocation = CLLocationCoordinate2DMake(location.latitude - topLeftCoordinate.latitude,
                                                                       location.longitude - topLeftCoordinate.longitude);

    CGPoint ret = CGPointMake((offsetLocation.latitude / latSpan) * planImageSize.width,
                              (offsetLocation.longitude / longSpan) * planImageSize.height);
    return ret;
}

然后将您的UIImageView引脚'center'属性设置为此方法返回的值。