KAR KAR - 1 year ago 92
iOS Question

MKMapView mathod 'didUpdateUserLocation' not calling

I have this code in my file,

@synthesize myLocation;

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

self.locationManager = [[CLLocationManager alloc] init];
myLocation.delegate = self;
[self.locationManager requestWhenInUseAuthorization];
[myLocation setShowsUserLocation: YES];


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

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
[self.myLocation setRegion:[self.myLocation regionThatFits:region] animated:YES];

But, method didUpdateUserLocation not calling.

I already added required frameworks in app.

I added everything in info.plist file. But still it is not calling.

This is my .h file,

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface MapView : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *myLocation;
@property(nonatomic, retain) CLLocationManager *locationManager;

Answer Source

I just solved the problem,

locationManager = [[CLLocationManager alloc] init];
    myLocation.delegate = self;
    [locationManager requestWhenInUseAuthorization];
    [locationManager startUpdatingLocation];
    [myLocation setShowsUserLocation: YES];

Use setShowUserLocation with value YES after startUpdatingLocation

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download