I need to place annotations according to their polar coordinate (with radius in pixels) originated at the user position. I use the following code snippet to do that.
CGPoint origin = [mapView convertCoordinate:userCoordinate toPointToView:mapView];
double dx = radius * cos(theta);
double dy = radius * sin(theta);
CGPoint point = CGPointMake(origin.x + dx, origin.y + dy);
NSLog(@"mapViewSize=(%f, %f), point=(%f,%f)", CGRectGetWidth(mapView.bounds), CGRectGetHeight(mapView.bounds), point.x, point.y);
return [mapView convertPoint:point toCoordinateFromView:mapView];
Here is an example of the NSLog
output:
mapViewSize=(228.000000, 228.000000), point=(40.817908,123.346518)
In my opinion, this would mean that the point is indeed located on the map view. However, when adding them back on the map after convertPoint:point toCoordinateFromView:
, it is placed very far (distance ~ 148847.221119 meters while the span of my region is just hundreds of meter) and therefore are out of the range of my map. What am I doing wrong?