User location in mapView doesn't show on several simulator devices (MapKit)

时间:2022-11-15 20:01:26

I've implemented a mapView that finds the user location and displays it, but the problem is that it doesn't work on iPhone 4S, iPhone 5, iPhone 5S, and iPhone 6 Plus in the iOS simulator, only on iPhone 6. The strange thing is that it works on my real iPhone 5S device.

我已经实现了一个查找用户位置并显示它的mapView,但问题是它在iOS模拟器中的iPhone 4S,iPhone 5,iPhone 5S和iPhone 6 Plus上不起作用,仅适用于iPhone 6。奇怪的是它适用于我真正的iPhone 5S设备。

Could this be a simulator problem or will this happen on real devices too?

这可能是模拟器问题还是会在真实设备上发生?

This is the warning that I receive:

这是我收到的警告:

Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.

尝试在不提示位置授权的情况下启动MapKit位置更新。必须首先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization]。

2 个解决方案

#1


0  

Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first

尝试在不提示位置授权的情况下启动MapKit位置更新。必须先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization]

What's the hard part here? Your map view cannot show the user's location until your app explicitly asks for authorization to use the user's location. The error message even shows you the methods, one of which you must call, in order to do that! How could it be any more helpful? Just do what it is telling you to do.

这里有什么难点?在您的应用明确要求授权使用用户位置之前,您的地图视图无法显示用户的位置。错误消息甚至会显示您必须调用的方法,以便执行此操作!怎么会有用呢?只是做它告诉你要做的事情。

Note that you must not only request authorization, you must receive authorization.

请注意,您不仅必须请求授权,还必须获得授权。

#2


0  

I ended up solving my own question.

我最终解决了自己的问题。

I just added this line of code in viewDidLoad:

我刚在viewDidLoad中添加了这行代码:

 [self.locationManager requestWhenInUseAuthorization];

This was very helpful: http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/

这非常有用:http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/

#1


0  

Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first

尝试在不提示位置授权的情况下启动MapKit位置更新。必须先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization]

What's the hard part here? Your map view cannot show the user's location until your app explicitly asks for authorization to use the user's location. The error message even shows you the methods, one of which you must call, in order to do that! How could it be any more helpful? Just do what it is telling you to do.

这里有什么难点?在您的应用明确要求授权使用用户位置之前,您的地图视图无法显示用户的位置。错误消息甚至会显示您必须调用的方法,以便执行此操作!怎么会有用呢?只是做它告诉你要做的事情。

Note that you must not only request authorization, you must receive authorization.

请注意,您不仅必须请求授权,还必须获得授权。

#2


0  

I ended up solving my own question.

我最终解决了自己的问题。

I just added this line of code in viewDidLoad:

我刚在viewDidLoad中添加了这行代码:

 [self.locationManager requestWhenInUseAuthorization];

This was very helpful: http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/

这非常有用:http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/