get nearest locations from my current location

安稳与你 提交于 2019-12-25 11:32:06

问题


I am currently developing a mobile application for iOS which consists a part that requires to determine the users current location and from current location, i want to find nearest locations.

Is there any way to implement this ??

I have done some coding for finding current location of user. here is my code snippet,

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:locationManager.location
                   completionHandler:^(NSArray *placemarks, NSError *error) {
                       NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");

                       if (error){
                           NSLog(@"Geocode failed with error: %@", error);
                           return;

                       }

                       CLPlacemark *placemark = [placemarks objectAtIndex:0];
                       NSLog(@"placemarks=%@",[placemarks objectAtIndex:0]);

But my problem is, how will i get nearest other locations ?? from my current location which i already fetched.

Thanks in advance.


回答1:


Try this...

MKPointAnnotation *ann=[MKPointAnnotaion alloc] init];
CLLocationCoordinate2D point = [ann coordinate];
myLocation = [[CLLocation alloc] initWithLatitude:point.latitude longitude:point.longitude];
CLLocationDistance nearByLocation=[yourCurrentLocation distanceFromLocation:myLocation];


来源:https://stackoverflow.com/questions/17545344/get-nearest-locations-from-my-current-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!