简体   繁体   English

Badoo重复-如何确定并跟踪IOS中用户的位置?

[英]Badoo repeat - How to determine and keep track of user's location in IOS?

I want to do the following. 我要执行以下操作。

  • Keep updating a user's location using Core Location and send that information to a database. 继续使用“核心位置”更新用户的位置,并将该信息发送到数据库。

I am creating an app like badoo so I need to know where a user is located at all times to know who is near them. 我正在创建一个类似badoo的应用程序,因此我需要始终知道用户在哪里,以了解谁在他们附近。

I did the following: 我做了以下工作:

I put the following code in applicationDidFinishLaunchWithOptions 我将以下代码放在applicationDidFinishLaunchWithOptions

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];

and then the following function in AppDelegate.m 然后在AppDelegate.m以下功能

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    self.currentLocation = newLocation;

    // send location to server

    if(newLocation.horizontalAccuracy <= 100.0f) { [locationManager stopUpdatingLocation]; }
}

Is that the most efficient way to do it? 这是最有效的方法吗?

How then can I use the longitude and latitude details and django to be able to tell who is near a user? 然后如何使用经度和纬度详细信息以及django来分辨谁在用户附近?

Thanks for your help! 谢谢你的帮助!

As for efficiency - it depends on what you mean. 至于效率-这取决于您的意思。 The method you describe doesn't allow the user to actually start the process of determining location - it starts when the app starts. 您描述的方法不允许用户实际启动确定位置的过程-它在应用启动时启动。 If that is your intent, then I see this as being efficient for the user to not take the time to start it. 如果这是您的意图,那么我认为这对于用户无需花时间启动它是有效的。

However, you have the code in the appdelegate file. 但是,您的代码位于appdelegate文件中。 For efficiency as to maintaining code, I would not agree to the pattern you have provided. 为了提高代码维护效率,我不同意您提供的模式。 A more efficient (in terms of development) it would be best to have a separate model handle the updates from the location manager and have the appdelegate create an instance of said model. 从开发的角度来看,更有效的方法是最好有一个单独的模型来处理来自位置管理器的更新,并让appdelegate创建该模型的实例。

Sorry - can't help with django. 抱歉-无法使用Django。

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

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