Matlab GPS +距离以米为单位

时间:2016-01-14 13:06:29

标签: matlab gps

如果我将距离x [m]和y [m]移离初始位置,我必须为给定的纬度(lat0)和经度(lon0)计算新的纬度(lat1)和经度(lon1)。例如:

clear all; clc;
%initial coordinates:
lat0=56;
lon0=5;

%moving away from lat0,lon0,
xcor=200; %[m]
ycor=100; %[m]

首先我使用此代码计算lat1和lon1 :(来源:Adding distance to a GPS coordinate

lat1=lat0+rad2deg((xcor/6372800))
lon1=lon0+rad2deg((ycor/6372800)/(cos(lat0)))
distance=sqrt(xcor^2+ycor^2)

现在我想用哈斯金方程检查我的答案:

dlat = deg2rad(lat1-lat0);
dlon = deg2rad(lon1-lon0);
lat0 = deg2rad(lat0);
lat1 = deg2rad(lat1);
a = (sin(dlat./2)).^2 + cos(lat0) .* cos(lat1) .* (sin(dlon./2)).^2;
c = 2 .* asin(sqrt(a));
distance_check=6372800*c

然而,与前三行代码中的计算距离相比,大多数情况下,半径距离与100+米不同。

此代码出了什么问题?

1 个答案:

答案 0 :(得分:1)

在第一行代码中,第二行cos(lat0)必须为cos(deg2rad(lat0))

相关问题