Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在UIView中将地理坐标转换为CGPoint并绘制直线_Iphone_Ipad_Ios6_Uiview_Coordinate Systems - Fatal编程技术网

Iphone 在UIView中将地理坐标转换为CGPoint并绘制直线

Iphone 在UIView中将地理坐标转换为CGPoint并绘制直线,iphone,ipad,ios6,uiview,coordinate-systems,Iphone,Ipad,Ios6,Uiview,Coordinate Systems,我有一组CGP点,这些点是通过转换从核心位置框架代理方法获得的地理坐标获得的。集合是一组起点/终点 我从CoreLocation委托方法获取坐标 CLLocationCoordinate2D coordinate; CLLocationDegrees latitude; CLLocationDegrees longitude; - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)l

我有一组CGP点,这些点是通过转换从核心位置框架代理方法获得的地理坐标获得的。集合是一组起点/终点

我从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的CG点。UIView帧大小为(0,07681004)

这是我做的缩放

- (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);
}
其中
#定义地球半径6371


线条图不正确,因为在某些地方转换为CGPoint可能是错误的。我做错了什么。需要帮助。

有关将CLLocationCoordinate2D转换为CGPoint的信息,请参见此处的答案-

您可以将视图缩放到(宽度、高度),然后您可以指定0到1的坐标间隔(以百分比表示)我已经把地理坐标转换成屏幕坐标(CGPoint)并画了线。缩放部分是我最困难的地方。数学不是很好。然后使用CGAffineTransformMakeScale将视图缩放到视图大小(通过传递视图的宽度和高度),然后用百分比指定经度和纬度,例如经度0=0.5,90=0.75,就像这样…这样是否有效?你能写下答案吗?