views:

29

answers:

1

Hi, I'm trying to put an Annotation the lower left corner of currently visible map region, although the following code

CLLocationCoordinate2D origin = getOriginOfRegion(mapView.region);
[[[SimpleAnnotation alloc] initWithCoords:origin] autorelease];
...
extern CLLocationCoordinate2D getOriginOfRegion(MKCoordinateRegion region){
    return CLLocationCoordinate2DMake(region.center.latitude-region.span.latitudeDelta/2,
                                  region.center.longitude-region.span.longitudeDelta/2);
}

where SimpleAnnotation is as simple as it gets; puts the pin point a few degrees off the actual corner:

On the right side zoom level is higher, and as you can see the mistake is significantly smaller.

I've tried doing some math to counter it, considering that the error may be something related to projecting elliptical coordinates onto a plane, but didn't come up with anything useful.

Has anyone solved this problem? I've noticed that latitude values are not 'linear' on a mapView, I need some hints to understand how to transform them.

+2  A: 

I don't know if this will work but I suggest you try letting the map view convert view coordinates to map coordinates with convertPoint:toCoordinateFromView:.

For example:

CGPoint bottomLeftPoint = CGPointMake(CGRectGetMinX(map.bounds), CGRectGetMaxY(map.bounds));
CLLocationCoordinate2D bottomLeftCoord = [map convertPoint:bottomLeftPoint toCoordinateFromView:map];
Ole Begemann
I believe this would work, but I'm trying to understand the math behind it.
Pyetras
I can't explain it. According to Wikipedia, the length of one degree of latitude varies only very slightly (about 1%) between the equator and the poles.
Ole Begemann