简体   繁体   English

是否可以在IOS中将用户位置与背景中的特定位置保持距离?

[英]Is it possible to get distance from user location to specific location in background in IOS?

I need to calculate distance from user location to specific location, when the app is in background, and get a local notification based on that. 当应用程序处于后台时,我需要计算从用户位置到特定位置的距离,并根据该位置获取本地通知。

Background location tracking is totally possible, and I have already done that, but is it possible to execute a block of code, containing some condition checking and based on that update and get a local notification? 后台位置跟踪是完全可能的,我已经这样做了,但是是否可以执行一段代码,包含一些条件检查并基于该更新并获得本地通知?

I am not getting any proper solution. 我没有得到任何适当的解决方案。 Is there any way to do so? 有没有办法这样做?

Can you help me please? 你能帮我吗?

Start with the Location Awareness Programming Guide . 位置感知编程指南开始 Most everything you need to know is in there. 你需要知道的大部分内容都在那里。 (Most things that aren't in there are simply impossible for an AppStore app.) See also Tracking the User's Location in the iOS App Programming Guide . (对于AppStore应用程序,大多数不在其中的东西根本不可能。)另请参阅iOS应用程序编程指南中的跟踪用户位置。

The best tool for what you're describing is likely "Shape-Based Regions." 您所描述的最佳工具可能是“基于形状的区域”。 You can basically draw a box on a map and say "when the user enters or leaves this box, let me know." 您基本上可以在地图上绘制一个框并说“当用户进入或离开此框时,请告诉我。” If at all possible, this is the tool you should use. 如果可能的话,这是你应该使用的工具。 It has the least impact on battery life. 它对电池寿命的影响最小。

If you absolutely cannot solve the problem any other way, it is legal to request background location delivery with startUpdatingLocation (and the appropriate background mode in Info.plist; see the above docs). 如果您无法以任何其他方式解决问题,请使用startUpdatingLocation (以及Info.plist中的相应背景模式;请参阅上述文档)请求后台位置交付是合法的。 An app that tracks your route while you hike would be be appropriate for this kind of setup. 在您徒步旅行时跟踪您的路线的应用程序将适合此类设置。 But you should avoid it if at all possible since it's a major battery drain. 但是如果可能的话,你应该避免它,因为这是一个主要的电池消耗。

Yeah, you can definitely do that. 是的,你绝对可以做到这一点。 I'm doing it in an app right now. 我现在正在一个应用程序中这样做。 Use significant location changes, or regions, as previously suggested, to keep the pressure off the users battery as much as possible. 如前所述,使用重要的位置更改或区域,以尽可能地减轻用户电池的压力。

We observe regions (and significant location changes where regions are not supported by the device) then check a few things and fire off a local notification if needs be. 我们观察区域(以及设备不支持区域的重要位置变化)然后检查一些事情并在需要时发出本地通知。

We started with a basic prototype to prove the concept and I highly recommend that approach as a way to get familiar with the location and notification frameworks. 我们从一个基本原型开始来证明这个概念,我强烈建议这种方法来熟悉位置和通知框架。

You will want to update for significant locations in the background: http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-background-location/ . 您需要在后台更新重要位置: http//mobile.tutsplus.com/tutorials/iphone/ios-multitasking-background-location/ Then you will want to create a location notification based on that. 然后,您将需要基于此创建位置通知。

My issue is that I am not sure if you can create a local notification in the background. 我的问题是我不确定您是否可以在后台创建本地通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM