2016-09-06 60 views
0

我有這樣的代碼在我的文件,的MKMapView馬託 'didUpdateUserLocation' 不是要求

@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]; 
} 

但是,方法didUpdateUserLocation不是要求。

我已經在應用程序中添加了必需的框架。

我在info.plist文件中添加了所有內容。但它仍然沒有呼喚。

這是我的.h文件中,

#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; 
@end 
+0

您是否添加了委託? (CLLocationManagerDelegate)請發佈你的類實例。 – Andrei

+0

'MKMapView'對象在哪裏?在哪裏設置代表? – Larme

+0

添加了所有問題。 @Larme – KAR

回答

1

我只是解決了這個問題,

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

使用setShowUserLocation與價值YESstartUpdatingLocation

0

兄弟我想你的code.The委託方法不被調用。

然後我發現你沒有在viewDidLoad方法的末尾添加下面的解決方案。請加

[self.locationManager startUpdatingLocation]; 

我上面viewDidLoad方法,成功調用委託方法行代碼添加後。

1

您還沒有調用的方法更新位置又是那麼的委託方法沒有被召喚。您需要致電startUpdatingLocation

For Objective - C: 

[locationManager startUpdatingLocation]; 

For Swift: 

locationManager.startUpdatingLocation() 
相關問題