File Exchange

## pos2dist

version 1.0 (1.86 KB) by

Calculate distance between two points on earth's surface given by latitude-longitude pair.

Updated

Calculate distance between two points on earth's surface given by their latitude-longitude pair. Choose method 1 or 2. Method 1 uses plane approximation, only for points within several tens of kilometers; Method 2 calculates sphereic geodesic distance for points farther apart, but ignores flattening of the earth. Output is in km.

Shi Su

LR

LR

### LR (view profile)

You could also use the built-in function DISTANCE from the Mapping Toolbox:
dist = DISTANCE(LON1,LAT1,LON2,LAT2,ELLIPSOID)
For the Earth:
ELLIPSOID = [6378.1 km (semimajor axis), 0.00335 (eccentricity)]

Isabel Lima

### Isabel Lima (view profile)

Thanks a lot. Great function!

Stephen Cobeldick

### Stephen Cobeldick (view profile)

Those are some of the strangest FEX tags that I have ever seen:

but i dont run the function
distance
how many inputs i need
how many inputs i need 4
latitude
longitude
points
surface

shen

### shen (view profile)

Thank you very much.It is excellent but please check there might be a small error when there are only four input variables.

Tom

### Tom (view profile)

thank you, it works great!

star

### star (view profile)

Thank you for the useful function

Joachim

### Joachim (view profile)

Good work

Ioannis Daliakopoulos

### Ioannis Daliakopoulos (view profile)

line 36 should be

method = 1;

method == 1;

otherwise, very useful!

Rossella Blatt

### Rossella Blatt (view profile)

Thanks. I was about to write the same function, but then I found it here: you made save some time! :)

Rafael Palacios

### Rafael Palacios (view profile)

David Terr

That's much better! Keep up the good work.

Langqiu Sun

Appologize for the former one. That's imcomplete. A new version has been uploaded. This should be OK.

David Terr

This looks like it could be a great program but as is, it doesn't do anything! In fact, I had to add a couple lines to the end to keep it from returning an error message. Please test your code before submitting it!

Dave

MATLAB 6.5 (R13)