Calculate Distance from GPS coordinates
110 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have 2 columns in a spreadsheet representing the latitude and longitude.
How can I calculate the distance for between the the gps coordinates (eg distance between row 1 and row 2) using the formula
d=ACOS(cos(RADIANS(90-Lat1))*cos(RADIANS(90-Lat2))+sin(RADIANS(90-Lat1))* sin(RADIANS(90-Lat2))*cos(RADIANS(Lon1-Lon2)))* 3958.76
Latitude Longitude
33.47914 -88.7943
33.47914 -88.7943
33.47915 -88.7943
33.47917 -88.7943
0 Commenti
Risposta accettata
Walter Roberson
il 15 Dic 2018
Modificato: Walter Roberson
il 15 Dic 2018
With vector Lat and Lon, and assuming you want the distance between adjacent gps points (as opposed to the distance of each point to each other point)
d = acos(cosd(90-Lat(1:end-1)) .* cosd(90-Lat(2:end)) + sind(90-Lat(1:end-1)) .* sind(90-Lat(2:end))) .* cosd(Lon(1:end-1)-Lon(2:end)) * 3958.76;
3 Commenti
Più risposte (2)
MathWorks Support Team
il 11 Lug 2023
Tthe distance function in Mapping Toolbox is an option. This function has the benefit of being able to calculate the geodesic distance for a given Earth ellipsoid model, such as the WGS84 model which is used for GPS coordinates. For example:
lat = [33.47914 33.47914 33.47915 33.47917];
lon = [-88.7943 -88.7943 -88.7943 -88.7943];
% Use WGS84 ellipsoid model
wgs84 = wgs84Ellipsoid;
% Calculate individual distances
d1 = distance(lat(1),lon(1),lat(2),lon(2),wgs84);
d2 = distance(lat(2),lon(2),lat(3),lon(3),wgs84);
d3 = distance(lat(3),lon(3),lat(4),lon(4),wgs84);
1 Commento
Cg Gc
il 5 Ago 2025
I have been using this function, but my points are really close, so I am getting a distance of 0.1209. This is fine, but what are the units on this number? km? miles? feet? inches? I know how far away my points are in km, but with thousands of points and further calculations to make, I would rather do the calculations in a loop. In order to do this, I need to know the units of the answer to the distance function. It says it is degrees, but that isn't helpful for when you need to convert that to distance on the ground.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!