iphoneobjective-cmkmapviewexc-bad-accessshowuserlocation

mkmapview showsUserLocation


Hey have a question here. I'm trying to do.

if (Map.showsUserLocation == YES) 
        {
            Map.showsUserLocation = NO;
        }

This is rather simple. When the app just started showsUserLocation is set to YES, but it takes time for the device to find the location. So if the user click showsUserLocation = NO before the location has been found (before the blue dot appear). EXC_BAD_ACCESS.

In google map, it has the protection code, before google map get the blue dot appear, it will disable you from pressing the showsUserLocation button by displaying the activityIndicator. Any idea how to do this? Thanks in advance.


Solution

  • MKMapViewDelegate has a method:

    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
    

    You can enable the button here, until then keep it disabled.