停止MKMapview的用户位置更新(蓝点)

时间:2022-10-08 21:20:04

I am using an instance of CLLocationManager as well as a MKMapView for my app. I have a button that on tapped, will trigger startUpdatingLocation of my Location Manager which allows me to receive new location updates via the didUpdateToLocation callback. I stop these updates once I am satisfied with the accuracy:

我正在为我的应用程序使用CLLocationManager的实例以及MKMapView。我有一个按钮,会触发我的位置管理器的startUpdatingLocation,它允许我通过didUpdateToLocation回调接收新的位置更新。一旦我对准确性感到满意,我就会停止这些更新:

[locationManager stopUpdatingLocation];
locationManager.delegate = nil;

The problem is, the GPS remains turned on as indicated by the arrow sign on the top right of the status bar. After further investigation, I realized that this is due to the fact that the mapView has showsUserLocation = YES, which means it will continue to receive updates, even if my own instance of locationManager has stopped the updating.

问题是,GPS仍然打开,如状态栏右上角的箭头指示所示。经过进一步调查,我意识到这是因为mapView有showsUserLocation = YES,这意味着它将继续接收更新,即使我自己的locationManager实例已停止更新。

Adding the following after my stopping of the updates turns off the GPS sign, but the blue dot obviously disappears (but I do want the current position there still for visualization).

在我停止更新后添加以下内容会关闭GPS标志,但蓝点显然会消失(但我确实希望当前位置仍然可视化)。

mapView.showsUserLocation = NO;

For my app, I need to use both CLLocationManager (to compute nearest POIs within a certain distance) and MKMapView (mainly for the display of these POIs as annotations around my locatiom). Is there a way to simply stop all GPS updates to both, and just freeze the blue dot at that point?

对于我的应用程序,我需要使用CLLocationManager(计算一定距离内的最近POI)和MKMapView(主要用于显示这些POI作为我的locatiom周围的注释)。有没有办法简单地停止所有GPS更新,只是冻结那个点上的蓝点?

I thought of disabling mapView.showsUserLocation totally, and drawing the CLLocation from the LocationManager to the mapView as a custom annotation, but I am not sure that is the best way. Any ideas?

我想完全禁用mapView.showsUserLocation,并将CLLocation从LocationManager绘制到mapView作为自定义注释,但我不确定这是最好的方法。有任何想法吗?

1 个解决方案

#1


1  

I think that once you are done updating location to the desired accuracy, dropping an annotation pin would be visual enough for the user to know the location selected. That is pretty standard among MKMapView usages.

我认为,一旦您完成了将位置更新到所需精度,删除注释引脚将足够直观,以便用户知道所选位置。这是MKMapView用法中的标准。

Another thing to think about, the location arrow actually persists for a period of time (depends on the kind of usage), even after you stop monitoring location. You can find how long it persists in the Location Guidelines from Apple, but just something to consider as well.

另一件需要考虑的事情是,位置箭头实际上会持续一段时间(取决于使用的类型),即使您停止监控位置也是如此。您可以在Apple的“位置指南”中找到它存在多长时间,但也需要考虑一些事项。

#1


1  

I think that once you are done updating location to the desired accuracy, dropping an annotation pin would be visual enough for the user to know the location selected. That is pretty standard among MKMapView usages.

我认为,一旦您完成了将位置更新到所需精度,删除注释引脚将足够直观,以便用户知道所选位置。这是MKMapView用法中的标准。

Another thing to think about, the location arrow actually persists for a period of time (depends on the kind of usage), even after you stop monitoring location. You can find how long it persists in the Location Guidelines from Apple, but just something to consider as well.

另一件需要考虑的事情是,位置箭头实际上会持续一段时间(取决于使用的类型),即使您停止监控位置也是如此。您可以在Apple的“位置指南”中找到它存在多长时间,但也需要考虑一些事项。