0

I've developed an iPhone application to parse data from an XML file. This data contains a set of longitudes and latitudes for different places.

How do I detect nearest of them according to my current location on the map and how do I set set a range to show places in this range?

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
  • 2
    You can use the `distanceFromLocation:` method, see [this answer](http://stackoverflow.com/q/3905896/154803) – progrmr Dec 09 '11 at 00:27
  • Possible duplicate of http://stackoverflow.com/questions/3905896/distancefromlocation-calculate-distance-between-two-points, http://stackoverflow.com/questions/2652167/how-do-i-calculate-the-distance-between-two-points-of-latitude-and-longitude – Adam Lear Dec 09 '11 at 06:30

3 Answers3

1
CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:myLatitude longitude:myLongitude];

CLLocation *myXmlLocation = [[CLLocation alloc] initWithLatitude:xmlLatitude longitude:xmlLongitude];

CLLocationDistance distance = [myLocation distanceFromLocation: myXmlLocation];

This is in meters, so you must do any converting from there. They are also linear, so these aren't driving direction lengths by any means. Good luck.

Vinnie
  • 1,670
  • 14
  • 16
0

some trig, but really not too difficult.

this page has an example script, not in your language, but it contains explainations and the equations you need.

http://www.movable-type.co.uk/scripts/latlong.html

and also, please don't write run-on sentences, it took me a while to read your question.

mugetsu
  • 4,228
  • 9
  • 50
  • 79
0

@Vinnie said is absolutely right but these values is air distance.

Also this method is deprecated in iOS 3.2

- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location Parameters

You can't find the distance based on roads with the Apple SDK. Try to use google APIs for finding distance between two points on earth on roads.

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
Anil Kothari
  • 7,653
  • 4
  • 20
  • 25