【发布时间】:2013-06-16 20:39:51
【问题描述】:
我有一个从核心位置框架工作委托方法获得的转换地理坐标获得的 CGPoints 集合。集合是一组起点/终点。
我正在从 CoreLocation 委托方法获取坐标
CLLocationCoordinate2D coordinate;
CLLocationDegrees latitude;
CLLocationDegrees longitude;
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation *location = [locations lastObject];
latitude = location.coordinate.latitude;
longitude = location.coordinate.longitude;
}
我正在将当前的经纬度转换为 CGPoint,如下所示
CGPoint startPoint = [mapView convertCoordinate:retrievedCoordinate toPointToView:self.view];
CGPoint endPoint = [mapView convertCoordinate:retrievedEndCoordinate toPointToView:self.view];
我需要根据集合中的值在我的 UIView 上画线。如何正确调整/缩放相对于 UIView 的 CGPoints。 UIView 帧大小为 (0, 0, 768, 1004)。
这是我做的缩放
- (CGPoint)convertLatLongCoord:(CGPoint)latLong {
CGSize screenSize = [UIScreen mainScreen].applicationFrame.size;
CGFloat SCALE = MIN(screenSize.width, screenSize.height) / (2.0 * EARTH_RADIUS);
CGFloat OFFSET = MIN(screenSize.width, screenSize.height) / 2.0;
CGFloat x = EARTH_RADIUS * cos(latLong.x) * cos(latLong.y) * SCALE + OFFSET;
CGFloat y = EARTH_RADIUS * cos(latLong.x) * sin(latLong.y) * SCALE + OFFSET;
return CGPointMake(x, y);
}
在哪里#define EARTH_RADIUS 6371
线条图不正确,因为在某处转换为 CGPoint 可能是错误的。我究竟做错了什么。需要帮助。
【问题讨论】:
-
您可以做的一件事是将您的视图缩放到(宽度,高度),然后您可以指定您的坐标为 0 到 1(以百分比表示)并使用一些函数来转换您的经度和纬度到你的坐标。
-
我已经将地理坐标转换为屏幕坐标(CGPoint)并绘制了线条。缩放部分是我遇到最大困难的地方。数学不太好。
-
然后使用 CGAffineTransformMakeScale 将您的视图缩放到您的视图大小(通过传递视图宽度和高度),然后您指定经度和纬度的百分比,例如经度 0 = 0.5 , 90 = 0.75 像这样.. .
-
效果好吗?你能写出答案吗?
标签: iphone ipad ios6 uiview coordinate-systems