问题
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:
来源:https://stackoverflow.com/questions/33219544/how-to-show-locations-of-friends-on-map-near-by-20-km-from-user-current-location