Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 312
Hectoret Avatar asked Jan 25 '26 01:01

Hectoret


1 Answers

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

firstLongitude = 30.0;
firstLatitude = 30.0;

secondLongitude = 40.0;
secondLatitude = 40.0;

CLLocation *firstLoc = [[CLLocation alloc]initWithLatitude:firstLatitude longitude: firstLongitude];
CLLocation *secondLoc = [[CLLocation alloc]initWithLatitude:secondLatitude longitude: secondLongitude];

double distanceInMeters = [firstLoc getDistanceFrom: secondLoc];
like image 130
oxigen Avatar answered Jan 26 '26 16:01

oxigen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!