I have an MKMapView which allows the user to scroll the map around. Later, I want to get the latitude and longitude of the point at the center of the map, but can't find an easy way to do it. At the moment I'm trying something like:
CLLocationCoordinate2D centre = [locationMap convertPoint:locationMap.center toCoordinateFromView:locationMap];
txtLatitude.text = [NSString stringWithFormat:@"%f",centre.latitude];
txtLongitude.text = [NSString stringWithFormat:@"%f",centre.longitude];
But it's not working - both latitude and longitude both come out as zero. I'd be grateful for any ideas anyone might have!
==============
-- Update 1 --
Oh. If I add the:
NSLog(@"%@", locationMap);
line as suggested below, the log shows "(null)". I've got the following in my header (amongst other things):
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
IBOutlet MKMapView *locationMap;
@property (nonatomic, retain) IBOutlet MKMapView *locationMap;
and the following in my methods file:
@synthesize locationMap;
This is compiling without any warnings or errors at present. Starting to wonder if I've missed something obvious?