如何在地图上显示距离用户当前位置20公里的地图上的位置 [英] How to show locations of friends on map near by 20 km from user current location in ios
本文介绍了如何在地图上显示距离用户当前位置20公里的地图上的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation]; (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:
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);
}
解决方案
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:
这篇关于如何在地图上显示距离用户当前位置20公里的地图上的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文