Shaker Samy Aly
Shaker Samy Aly

Reputation: 1

How to calculate distance to locations

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?

Upvotes: 0

Views: 337

Answers (3)

Anil Kothari
Anil Kothari

Reputation: 7733

@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.

Upvotes: 0

Vinnie
Vinnie

Reputation: 1740

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.

Upvotes: 1

mugetsu
mugetsu

Reputation: 4398

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.

Upvotes: 0

Related Questions