【发布时间】:2011-12-07 14:40:25
【问题描述】:
MKMapViewDelegate mapView:didUpdateUserLocation: 在 5.0 模拟器上运行时不会调用方法,即使设备设置中给出了所有位置权限。
使用 4.3 可以正常工作。
有什么想法吗?
【问题讨论】:
标签: ios mkmapview ios5 mkmapviewdelegate
MKMapViewDelegate mapView:didUpdateUserLocation: 在 5.0 模拟器上运行时不会调用方法,即使设备设置中给出了所有位置权限。
使用 4.3 可以正常工作。
有什么想法吗?
【问题讨论】:
标签: ios mkmapview ios5 mkmapviewdelegate
我在重构为 ARC 后得到了同样的结果。
首先我在 viewDidLoad 中有以下代码;
CLLocationManager *lm =[[CLLocationManager alloc] init];
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
[lm startUpdatingLocation];
我在头文件中做了以下操作
@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];
【讨论】:
检查“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>
【讨论】: