How to show locations of friends on map near by 20

2019-06-14 21:00发布

问题:

I want to get locations of my friends near by me within 20km.App should track my current location and when i want to search for friends within 20km,It should show All my friends location on map.

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:

Look into

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

and use this to get your current location:

  [locations lastObject];

and to get distance use this:

  distanceFromLocation: