如何在 ios 中显示距离用户当前位置 20 公里附近的朋友的位置
How to show locations of friends on map near by 20 km from user current location in ios
我想获取我附近朋友的位置 20km.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);
}
调查
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
并使用它来获取您当前的位置:
[locations lastObject];
要获得距离,请使用:
distanceFromLocation:
我想获取我附近朋友的位置 20km.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);
}
调查
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
并使用它来获取您当前的位置:
[locations lastObject];
要获得距离,请使用:
distanceFromLocation: