3
我有一个通过转换地理坐标获得的CGPoints的集合,这些地理坐标是通过Core Location框架工作委托方法获得的。该集合是一组开始/结束点。将地理坐标转换为CGPoint并在UIView中绘制线条
我获得从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相关的CGPoint。 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可能是错误的缩放。我究竟做错了什么。需要帮助。
一件事ü可以做的就是扩展你的视图(宽,高),那么在哪里指定坐标interms 0到1(以百分比方式)和使一些函数将你的经度和纬度转换成你的坐标。 –
我已将地理坐标转换为屏幕坐标(CGPoint)和绘制的线条。缩放部分是我遇到最困难的地方。数学不太好。 –
然后使用CGAffineTransformMakeScale缩放您的视图到您的视图大小(通过传递视图的宽度和高度),然后您指定经度和纬度的百分比,例如经度0 = 0.5,90 = 0.75像这样... –