繁体   English   中英

iOS CoreLocation plot 图像顶部的用户位置

[英]iOS CoreLocation plot user location on top of image

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

好吧,您首先使用 UIImageView 来显示某种类型的 pin 指针图标,然后使用 function 将纬度/经度坐标转换为图像上的 position。

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

- (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' 属性设置为此方法返回的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM