MKMapViewDelegate mapView:didUpdateUserLocation: 在 5.0 模拟器上运行时不会调用方法,即使设备设置中给出了所有位置权限。
使用 4.3 它工作正常。
有任何想法吗?
MKMapViewDelegate mapView:didUpdateUserLocation: 在 5.0 模拟器上运行时不会调用方法,即使设备设置中给出了所有位置权限。
使用 4.3 它工作正常。
有任何想法吗?
检查“setUserTrackingMode:animated:”和“userTrackingMode”。两者都是 iOS5 中的新功能。我遇到了类似的问题,并通过在 setUserTrackingMode 函数中设置 MKUserTrackingModeFollow 来修复它。我认为默认的跟踪模式是 MKUserTrackingModeNone 并且只调用一次 mapView:didUpdateUserLocation 。
如果您的问题是从未调用过 mapView:didUpdateUserLocation,那么请查看新 xcode 中的选项,在控制台输出的正下方有一个类似 ipad 中的 gps 图标的图标,可让您模拟位置。
我知道这是一个旧线程。无论如何我都会回答,它也可能对其他人有帮助。
我在 iOS 6 上遇到了类似的问题。我可以通过将 mapview 委托设置为 self 来解决这个问题。
像这样:
[mapView setDelegate:self];
确保您的 ViewController.h 具有 MKMapViewDelegate 沿线:
@interface ViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate>
重构为 ARC 后,我得到了同样的结果。
首先,我在 viewDidLoad 中有以下代码;
CLLocationManager *lm =[[CLLocationManager alloc] init];
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
[lm startUpdatingLocation];
我在 de 头文件中做了以下操作
@interface ViewController : UIViewController <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
@property(nonatomic, strong)CLLocationManager *locationManager;
和
@synthesize locationManager;
我在 viewDidLoad 中更改的代码
locationManager =[[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];