Search code examples
iosmkmapviewcllocation

MKMapView centerLocation


In my application there is an MKMapView and I am trying to get the center coordinates of the map region that is currently visible. I am using following method so that if user moves the visible region I'll get new center coordinates.

- (void)mapView:(MKMapView *)mapView1 regionDidChangeAnimated:(BOOL)animated
{

CLLocationCoordinate2D centre = [mapView centerCoordinate];

NSLog(@"MAP CENTER = %f,%f",centre.latitude,centre.longitude);
}

the problem is that when I switch to the UIViewController that contains MKMapView it gives MAP CENTER = 0.000000,0.000000 for two times then gives the actual coordinates MAP CENTER = 55.755786,37.617633. I want the actual coordinates as soon as I switch to that UIViewController.


Solution

  • Is the coordinates (55.755786,37.617633) your current location ?

    MKMapView takes some time to get a lock on GPS to fetch the coordinates for your current location. Until then centerCoordinate might return (0,0)