Calculate Distance from GPS coordinates

조회 수: 110 (최근 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