Calculate Distance from GPS coordinates

89 ビュー (過去 30 日間)
je
je 2018 年 12 月 14 日
コメント済み: Cg Gc 2025 年 8 月 5 日
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

採用された回答

Walter Roberson
Walter Roberson 2018 年 12 月 15 日
編集済み: Walter Roberson 2018 年 12 月 15 日
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 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 15 日
Fixed.
je
je 2018 年 12 月 15 日
Thank You, Walter.
Problem solved.

サインインしてコメントする。

その他の回答 (2 件)

Mark Sherstan
Mark Sherstan 2018 年 12 月 14 日
Look at this function here.

MathWorks Support Team
MathWorks Support Team 2023 年 7 月 11 日
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 件のコメント
Cg Gc
Cg Gc 2025 年 8 月 5 日
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.

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by