Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

iphone - GPS coordinates in degrees to calculate distances

On the iPhone, I get the user's location in decimal degrees, for example: latitude 39.470920 and longitude = -0.373192; That's point A.

I need to create a line with another GPS coordinate, also in decimal degrees, point B. Then, calculate the distance (perpendicular) between the line from A to B and another point C.

The problem is I get confused with the values in degrees. I would like to have the result in meters. What's the conversion needed? How will the final formula to compute this look like?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Why don't you use CLLocations distanceFromLocation: method? It will tell you the precise distance between the receiver and another CLLocation.

CLLocation *locationA = [[CLLocation alloc] initWithLatitude:12.123456 longitude:12.123456];
CLLocation *locationB = [[CLLocation alloc] initWithLatitude:21.654321 longitude:21.654321];

CLLocationDistance distanceInMeters = [locationA distanceFromLocation:locationB];

// CLLocation is aka double

[locationA release];
[locationB release];

It's as easy as that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...