MKMapViewDelegate mapView:didUpdateUserLocation: 在 iOS5 上未调用方法

发布于 2024-12-09 16:57:52 字数 131 浏览 1 评论 0原文

即使在设备设置中给出了所有位置权限,在 5.0 模拟器上运行时也不会调用 MKMapViewDelegate mapView:didUpdateUserLocation: 方法。

4.3 运行良好。

有什么想法吗?

MKMapViewDelegate mapView:didUpdateUserLocation: method is not called when running on the 5.0 simulator, even if all location permissions are given in the device settings.

With 4.3 it's working fine.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悲凉≈ 2024-12-16 16:57:52

重构 ARC 后我得到了同样的结果。

首先,我在 viewDidLoad 中有以下代码;

CLLocationManager *lm =[[CLLocationManager alloc] init];
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
[lm startUpdatingLocation];

我在 de headerfile 中执行了以下操作

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

I got the same thing after refactor to ARC.

First I had the following code in viewDidLoad;

CLLocationManager *lm =[[CLLocationManager alloc] init];
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
[lm startUpdatingLocation];

I did the following in de headerfile

@interface ViewController : UIViewController <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}

@property(nonatomic, strong)CLLocationManager *locationManager;

And

@synthesize locationManager;

The code I change in viewDidLoad

locationManager =[[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
暮光沉寂 2024-12-16 16:57:52

检查“setUserTrackingMode:animated:”和“userTrackingMode”。两者都是 iOS5 中的新增内容。我遇到了类似的问题,并通过在 setUserTrackingMode 函数中设置 MKUserTrackingModeFollow 来修复它。我认为默认的跟踪模式是 MKUserTrackingModeNone 并且只调用一次 mapView:didUpdateUserLocation 。

如果你的问题是mapView:didUpdateUserLocation从未被调用,那么看看新的xcode中的选项,在控制台输出的正下方有一个类似ipad中的gps图标的图标,它可以让你模拟一个位置。

Check "setUserTrackingMode:animated:" and "userTrackingMode". Both are new in the iOS5. I had a similar problem and fixed it by setting MKUserTrackingModeFollow in the setUserTrackingMode function. I think the default tracking mode is MKUserTrackingModeNone and only calls mapView:didUpdateUserLocation once.

If your problem is that the mapView:didUpdateUserLocation is never called, then take a look at the options in the new xcode, right below the console outputs there's an icon like the gps icon in the ipad, which lets you simulate a location.

人事已非 2024-12-16 16:57:52

我知道这是一个旧线程。无论如何我都会回答,这也可能对其他人有帮助。

我在 iOS 6 中遇到了类似的问题。我可以通过将 mapview delegate 设置为 self 来解决这个问题。

像这样:

[mapView setDelegate:self];

确保您的 ViewController.h 具有 MKMapViewDelegate :

@interface ViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate>

I know it's an old thread. I'll answer anyway, it might help others too.

I had similar problem with iOS 6. Which I was able to solve by setting the mapview delegate to self.

Like this:

[mapView setDelegate:self];

Make sure your ViewController.h has the MKMapViewDelegate along the lines:

@interface ViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文