您已经在您的问题中定义了正确执行此操作的方法。您需要将用户的坐标传递到 Web 服务中。Web 服务或存储过程应实现将结果过滤到仅附近事物的逻辑。如果您需要建议的特定部分,请澄清。
您真的应该让数据库引擎在这里完成繁重的工作。在 mySQL 中,你会使用这样的东西:
SELECT ((ACOS(SIN($lat * PI() / 180) * SIN(lat * PI() / 180) +
COS($lat * PI() / 180) * COS(lat * PI() / 180) * COS(($lon - lon) *
PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance
FROM members
HAVING distance<='10' ORDER BY distance ASC
以下是带有参数的 JSON 获取请求的一些 AFNetworking 代码注意(这是最相关的代码片段,不会单独执行):
NSString *latString = [NSString stringWithFormat:@"%f", lastLocation.coordinate.latitude];
NSString *lonString = [NSString stringWithFormat:@"%f", lastLocation.coordinate.longitude];
NSString *accString = [NSString stringWithFormat:@"%f", lastLocation.horizontalAccuracy];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:[defaults valueForKeyPath:@"sessionRP"] , @"sessionRP", [defaults valueForKeyPath:@"partnerID"], @"pid", appointment.scheduleRowPointer, @"srp", latString, @"lat", lonString, @"long", status, @"stat", @"0", @"cached", accString, @"acc", nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET" path:myPath parameters:params];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {