I have a collection of CGPoints obtained from converting geographic coordinates obtained form Core Location frame work delegate method. The collection is a set of start/end points.
I am obtaining the coordinates from CoreLocation delegate method
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;
}
I am converting the current latitude and longitude to CGPoint as below
CGPoint startPoint = [mapView convertCoordinate:retrievedCoordinate toPointToView:self.view];
CGPoint endPoint = [mapView convertCoordinate:retrievedEndCoordinate toPointToView:self.view];
I need to draw lines on my UIView based on the values in the collection. How can I adjust/scale correctly, the CGPoints with respect to the UIView. UIView frame size is (0, 0, 768, 1004).
This is the scaling I have done
- (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);
}
where #define EARTH_RADIUS 6371
The line drawing is not correct, since somewhere the conversion to CGPoint might be wrong. What am I doing wrong. Help needed.