0

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.

Krunal
  • 6,440
  • 21
  • 91
  • 155
  • go to [this Link](http://stackoverflow.com/questions/17085668/how-to-find-nearest-latitude-and-longitude-form-current-place), this has similar question. I guess this will help you. – Suryakant Sharma Jul 09 '13 at 10:18

1 Answers1

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];
Bhavin_m
  • 2,746
  • 3
  • 30
  • 49
  • How to intialize myLocation ? and what to put in place of `yourCurrentLocation` ? i have wrote my code snippet above for current location. – Krunal Jul 09 '13 at 11:10
  • check this [tutorial](http://mobileorchard.com/hello-there-a-corelocation-tutorial/) for get current location – Bhavin_m Jul 09 '13 at 11:19
  • dude i am getting current location but what to write in place of `yourCurrentLocation` ??? i wrote `locationManager.location` in place of `yourCurrentLocation` is it right ? – Krunal Jul 09 '13 at 11:25
  • lol, i am asking because i dont have real device now, i am testing it in simulator. – Krunal Jul 09 '13 at 11:36
  • `CLLocationDistance nearByLocation=[locationManager.location distanceFromLocation:myLocation]; NSLog(@"nearByLocation=%f",nearByLocation);` myLog shows some points like `8230614.551295` what are they ? – Krunal Jul 09 '13 at 11:36