Krunal
Krunal

Reputation: 6490

get nearest locations from my current location

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.

Upvotes: 0

Views: 1128

Answers (1)

Bhavin_m
Bhavin_m

Reputation: 2784

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];

Upvotes: 1

Related Questions