StartUpdatingLocation VS重大变更的位置服务 [英] StartUpdatingLocation Vs significant-change location service

查看:137
本文介绍了StartUpdatingLocation VS重大变更的位置服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于重大变更位置服务的问题。 苹果文档说:无论您使用标准位置服务还是重要更改位置服务来获取位置事件,您接收这些事件的方式都是相同的。 / p>

但在重大变更位置服务的情况下,我无法获得任何
我在标准位置服务情况下获得的任何回电请让我知道是否有人有任何输入?

解决方案

startUpdatingLocation 当它被第一次调用,然后当距离过滤器值超过时。

但是当 startMonitoringSignificantLocationChanges 发生重大变化时发生位置发生。



请检查 CLLocationManager 了解详情。



< blockquote>

startUpdatingLocation



开始生成报告用户当前
位置的更新。 p>

- (void)startUpdatingLocation Discussion



立即。调用此方法会导致
位置管理器获取初始位置修正(可能需要几秒钟
),并通过调用其
locationManager:didUpdateLocations:方法来通知您的委托。 (在iOS 5和更早版本中,
位置管理器调用
locationManager:didUpdateToLocation:fromLocation:方法。)
之后,接收器主要在
值生成更新事件在distanceFilter属性中被超过。不过,在其他情况下,更新可能是
。例如,如果硬件收集到更准确的
位置读数,则接收方可以
发送另一个通知。



连续几次调用此方法不会自动
导致生成新事件。然而,在
之间调用stopUpdatingLocation确实会导致在您调用此方法的下一个
时间内发送新的初始事件。



如果您启动此服务和您的应用程序被暂停,
系统会停止事件的发送,直到您的应用程序再次运行
(在前台或后台)。如果您的
应用程序终止,则新位置事件的交付将完全停止
。因此,如果您的应用程序需要在后台接收位置
事件,则它必须在其Info.plist文件中包含UIBackgroundModes
键(具有位置值)。



除了实现
locationManager:didUpdateLocations:方法的委托对象外,它还应实现
locationManager:didFailWithError:方法来响应潜在的
错误。 / p>







startMonitoringSignificantLocationChanges



开始根据重要位置
更改生成更新。 - (void)startMonitoringSignificantLocationChanges Discussion



此方法异步启动位置事件的传递,
在您调用后不久返回。位置事件被传递到
您的委托的locationManager:didUpdateLocations:方法。要交付的第一个
事件通常是最近缓存的位置
事件(如果有的话),但在某些情况下可能是较新的事件。
获取当前的位置修正可能需要几秒钟的时间,
,所以一定要检查
委托方法中位置事件的时间戳。



返回当前位置修正后,只有在检测到用户位置的显着变化为
时,接收器才会生成更新
事件。例如,当设备
变为与不同的蜂窝塔关联时,它可能会生成一个新事件。它不依赖于
distanceFilter属性中的值来生成事件。调用
这个方法连续多次不会自动产生
在新的事件被产生。然而,在
stopMonitoringSignificantLocationChanges之间调用
会导致在您下次调用此
方法时发送新的初始事件。



如果您启动此服务,并且您的应用程序随后终止
,则系统会在新事件到达时自动将应用程序重新启动为
背景。在这种情况下,选项
字典传递给
的locationManager:didUpdateLocations:方法,您的应用程序委托包含键
UIApplicationLaunchOptionsLocationKey,表示您的
应用程序已启动,因为定位事件。在重新启动后,
仍然必须配置位置管理器对象,并调用此
方法继续接收位置事件。当您重新启动
位置服务时,当前事件会立即传送到您的委托
。此外,在您开始定位服务之前,您的位置
管理器对象的位置属性将使用最近的位置对象(即使是
)填充。



除了实现
locationManager:didUpdateLocations:方法的委托对象外,它还应该实现
locationManager:didFailWithError:方法来响应潜在的
错误。



注意:只要设备从之前的通知中移动500美元b美元b米或更多,应用程序就会收到通知。它不应该比每五分钟更频繁地预期
通知。如果
设备能够从网络中检索数据,位置管理器
更有可能及时发送通知。



I am having issue regarding significant-change location service.

Apple documentation says "Whether you use the standard location service or the significant-change location service to get location events, the way you receive those events is the same."

but in case of "significant-change location service" I am not able to get any callbacks which I get in case of "standard location service" Please let me know if anybody has any inputs?

解决方案

startUpdatingLocation updates the location when it is called first time and then when the distance filter value exceeds.

But the startMonitoringSignificantLocationChanges when a significant change in position occurs.

Please check CLLocationManager for the details.

startUpdatingLocation

Starts the generation of updates that report the user’s current location.

- (void)startUpdatingLocation Discussion

This method returns immediately. Calling this method causes the location manager to obtain an initial location fix (which may take several seconds) and notify your delegate by calling its locationManager:didUpdateLocations: method. (In iOS 5 and earlier, the location manager calls the locationManager:didUpdateToLocation:fromLocation: method instead.) After that, the receiver generates update events primarily when the value in the distanceFilter property is exceeded. Updates may be delivered in other situations though. For example, the receiver may send another notification if the hardware gathers a more accurate location reading.

Calling this method several times in succession does not automatically result in new events being generated. Calling stopUpdatingLocation in between, however, does cause a new initial event to be sent the next time you call this method.

If you start this service and your application is suspended, the system stops the delivery of events until your application starts running again (either in the foreground or background). If your application is terminated, the delivery of new location events stops altogether. Therefore, if your application needs to receive location events while in the background, it must include the UIBackgroundModes key (with the location value) in its Info.plist file.

In addition to your delegate object implementing the locationManager:didUpdateLocations: method, it should also implement the locationManager:didFailWithError: method to respond to potential errors.


startMonitoringSignificantLocationChanges

Starts the generation of updates based on significant location changes.

- (void)startMonitoringSignificantLocationChanges Discussion

This method initiates the delivery of location events asynchronously, returning shortly after you call it. Location events are delivered to your delegate’s locationManager:didUpdateLocations: method. The first event to be delivered is usually the most recently cached location event (if any) but may be a newer event in some circumstances. Obtaining a current location fix may take several additional seconds, so be sure to check the timestamps on the location events in your delegate method.

After returning a current location fix, the receiver generates update events only when a significant change in the user’s location is detected. For example, it might generate a new event when the device becomes associated with a different cell tower. It does not rely on the value in the distanceFilter property to generate events. Calling this method several times in succession does not automatically result in new events being generated. Calling stopMonitoringSignificantLocationChanges in between, however, does cause a new initial event to be sent the next time you call this method.

If you start this service and your application is subsequently terminated, the system automatically relaunches the application into the background if a new event arrives. In such a case, the options dictionary passed to the locationManager:didUpdateLocations: method of your application delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your application was launched because of a location event. Upon relaunch, you must still configure a location manager object and call this method to continue receiving location events. When you restart location services, the current event is delivered to your delegate immediately. In addition, the location property of your location manager object is populated with the most recent location object even before you start location services.

In addition to your delegate object implementing the locationManager:didUpdateLocations: method, it should also implement the locationManager:didFailWithError: method to respond to potential errors.

Note: Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.

这篇关于StartUpdatingLocation VS重大变更的位置服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆