2

I am working on Xcode project and I got some problems. In my app, I have a GPS location and I got some taxi service around in 1000 meters radius. I would like to find the closest service near by me. The taxi service location is parsed from JSON. It look like that

NSNumber * latitude = [[diction objectAtIndex:13]objectAtIndex:1];
NSLog(@"lng is =>%@", latitude);
NSNumber * longitude = [[diction objectAtIndex:13]objectAtIndex:2];
NSLog(@"lat is =>%@", longitude);

Moreover, I have my own location like that:

[locationManager stopUpdatingLocation];
NSLog(@"latitude: %f", newLocation.coordinate.latitude);
NSLog(@"longitude: %f", newLocation.coordinate.longitude);

How can I subtract the latitude and longitude above in order to find the closest service. Best Regards.

Jano
  • 62,815
  • 21
  • 164
  • 192
Kuc Ku
  • 51
  • 1
  • 6

1 Answers1

2
 CLLocation *oldLocation = [[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]];
    double distance = [newLocation distanceFromLocation:oldLocation];

use this may help You, thanks.

Nookaraju
  • 1,668
  • 13
  • 24
  • Hi, I did not clearly understand your code, the oldLocation means the current location? and the newLocation is the location of services around right? Base on my code, we have: CLLocation *newLocation = [[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]]; is that correct? lat and long in newLocation is the value that I got from JSON data. Thanks again and I deeply appreciate your help. – Kuc Ku Mar 11 '13 at 16:39