如何在距离用户当前位置20公里附近的地图上显示朋友的位置

时间:2015-10-19 16:34:59

标签: ios objective-c dictionary apple-maps

我希望在20公里范围内获取我的朋友的位置.App应该跟踪我当前的位置,当我想在20公里内搜索朋友时,它应该在地图上显示我所有朋友的位置。

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];

 -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);

}

1 个答案:

答案 0 :(得分:1)

查看

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;

并使用它来获取您当前的位置:

  [locations lastObject];

并且要远距离使用它:

  distanceFromLocation: