# how can I get the distance between two points in geoscatter

4 views (last 30 days)
flashpode on 1 Feb 2022
Answered: Divit on 18 Sep 2023
Hello, so I got a variable of latitud and another of longitud and a latitud and langitud from a point in the map. What I want is to calculate the distance between each point of the variables to the point I got in geoscatter. How can I do it?

Divit on 18 Sep 2023
Hi,
I understand that you would like to calculate distance between a reference point and a list of points in geoscatter.
% Define latitude and longitude arrays for your points
lat_array = [latitude1, latitude2, latitude3, ...]; % Replace with your values
lon_array = [longitude1, longitude2, longitude3, ...]; % Replace with your values
% Define the latitude and longitude of your reference point
ref_lat = reference_latitude; % Replace with your value
ref_lon = reference_longitude; % Replace with your value
% Convert latitude and longitude values to radians
% Radius of the Earth in kilometers (mean value)
% Initialize an array to store distances
distances_km = zeros(size(lat_array));
% Calculate distances using the Haversine formula
for i = 1:length(lat_array)
c = 2 * atan2(sqrt(a), sqrt(1-a));
end
The distances_km array contains the distances between the reference point and each point in your lat_array and lon_array.
To understand more, refer to the following documentation links:
I hope you find it useful.