GeoDistance[{lat1,lon1},{lat2,lon2}]
gives the geodesic distance between latitude-longitude positions on the Earth.
GeoDistance[loc1,loc2]
gives the distance between locations specified by position objects or geographical entities.
GeoDistance[{loc1,…,locn}]
gives the total distance from loc1 to locn through all the intermediate loci.
GeoDistance
GeoDistance[{lat1,lon1},{lat2,lon2}]
gives the geodesic distance between latitude-longitude positions on the Earth.
GeoDistance[loc1,loc2]
gives the distance between locations specified by position objects or geographical entities.
GeoDistance[{loc1,…,locn}]
gives the total distance from loc1 to locn through all the intermediate loci.
Details and Options
- GeoDistance[loc1,loc2] gives the distance between locations loc1 and loc2 as measured along the geodesic joining them on the surface of the reference ellipsoid. Heights are ignored.
- The result is returned as a Quantity object with dimensions of length. The unit used can be chosen with the option UnitSystem, which has $UnitSystem as default value.
- Latitudes and longitudes can be given as numbers in degrees, as DMS strings, or as Quantity angles.
- Position objects in GeoDistance[loc1,loc2] can be given as GeoPosition, GeoPositionXYZ, GeoPositionENU, or GeoGridPosition objects.
- In GeoDistance[loc1,loc2], the loci can be Entity objects with domains such as "City", "Country" and "AdministrativeDivision". Time-dependent entities of domains such as "HistoricalCountry" and "MilitaryConflict" can also be used.
- For entities corresponding to extended geographic regions, GeoDistance by default computes the minimum distance between any points in the regions.
- For time-dependent entities, GeoDistance by default computes the distance corresponding to the moment of closest approach between them.
- GeoDistance[loc1,loc2] by default uses the reference ellipsoid associated with the datum for loc1.
- GeoDistance automatically threads over lists of locations or GeoPosition arrays, so that GeoDistance[loc,locs] returns a list of distances, and GeoDistance[locs1,locs2] returns a matrix of distances. Results are given as QuantityArray objects.
- GeoDistance and GeoDirection, or their combination in GeoDisplacement, solve the geodetic inverse problem.
- GeoDistance has option DistanceFunction, with the following settings:
-
"Boundary" minimum distance between any points in regions "Center" distance between centers of regions "SignedBoundary" distance to boundary, negative for interior points - GeoDistance by default uses the setting DistanceFunction"Boundary".
Examples
open all close allBasic Examples (6)
Distance between two positions on the reference ellipsoid:
GeoDistance[{37, -109}, {40.113, -88.261}]GeoDistance[Entity["City", {"Chicago", "Illinois", "UnitedStates"}], Entity["City", {"Tokyo", "Tokyo", "Japan"}]]Distance between two fully specified geodetic positions:
GeoDistance[GeoPosition[{37, -109, 150}, "ITRF00"], GeoPosition[{40.113, -88.261, 192.868}, "ITRF00"]]Distance between two historical entities at the time of their closest approach:
GeoDistance[Entity["MilitaryConflict", "BattleOfZama"], Entity["HistoricalCountry", "RomanRepublic"]]Distances from a location to a list of different locations:
GeoDistance[{37, -109}, {{40.113, -88.261}, Entity["City", {"Chicago", "Illinois", "UnitedStates"}], GeoPosition[{38.52, -85.23}]}]Normal[%]Total distance between several locations:
GeoDistance[{Entity["City", {"LosAngeles", "California", "UnitedStates"}], Entity["City", {"Dallas", "Texas", "UnitedStates"}], Entity["City", {"Miami", "Florida", "UnitedStates"}]}]Scope (11)
Geographic Data (8)
Distance between any two points on the Earth, using the parameters of the default datum "ITRF00":
GeoDistance[{46.42, -21.02}, {-30.23, 40.51}]Angles can also be specified as DMS strings:
GeoDistance["46°25'12''N 21°1'12''W", {"30°13'48.''S", "40°30'36.''E"}]Or as Quantity objects:
GeoDistance[{Quantity[46.42, "AngularDegrees"], Quantity[-21.02, "AngularDegrees"]}, {Quantity[-30.23, "AngularDegrees"], Quantity[40.51, "AngularDegrees"]}]Compute the distance between Entity objects:
GeoDistance[Entity["Country", "Spain"], Entity["Country", "Germany"]]Or between an Entity object and a geo position:
GeoDistance[GeoPosition[{40, -4}], Entity["Country", "Germany"]]Distance between geodetic positions, in different formats:
p = GeoPosition[{46.42, -21.02}]q = GeoGridPosition[{0.7, 0.9}, "Mercator"]GeoDistance[p, q]GeoDistance[GeoPositionXYZ[p], GeoPositionENU[q, GeoPosition[{0, 0}]]]Compute distances from a common location to a list of positions, in any format:
GeoDistance[Here, {{0, 0}, Entity["City", {"Paris", "IleDeFrance", "France"}], GeoPosition[{40, 20}], GeoGridPosition[{40, 20}, "Mercator"]}]Normalize the resulting QuantityArray object:
Normal[%]Compute a matrix of distances between two lists of locations:
SeedRandom[1234];
locs1 = RandomGeoPosition[100];
locs2 = RandomGeoPosition[200];AbsoluteTiming[dists12 = GeoDistance[locs1, locs2]]Computing all individual distances separately is slower:
AbsoluteTiming[outer = Outer[GeoDistance, locs1["Data"], locs2["Data"], 1];]dists12 == outerHeight and time information is ignored in GeoDistance computations:
GeoDistance[GeoPosition[{20, 30, 100}], GeoPosition[{-20, -30, 200, 3.6 10 ^ 9}]]% === GeoDistance[GeoPosition[{20, 30}], GeoPosition[{-20, -30}]]Points in different datums. The datum of the second point is changed to the datum of the first:
GeoDistance[GeoPosition[{30., 40.}, "ITRF90"], GeoPosition[{-50., -60.}, "WGS72"]]GeoDistance[GeoPosition[{30., 40.}], GeoPosition[{-50., -60.}]]UnitConvert[% - %%, "Meters"]Total distance between several locations:
GeoDistance[{Entity["City", {"LosAngeles", "California", "UnitedStates"}], GeoPosition[{40, -90}], Entity["City", {"Miami", "Florida", "UnitedStates"}]}]% == GeoDistance[Entity["City", {"LosAngeles", "California", "UnitedStates"}], GeoPosition[{40, -90}]] + GeoDistance[GeoPosition[{40, -90}], Entity["City", {"Miami", "Florida", "UnitedStates"}]]Historical Data (3)
The distance between two historical entities is the minimum distance between their territories at the same time:
GeoDistance[Entity["HistoricalCountry", "RomanRepublic"], Entity["HistoricalCountry", "HanDynasty"]]Using the GeoVariant "UnionArea" performs the computation, ignoring temporal information:
GeoDistance[Entity["HistoricalCountry", "RomanRepublic"], GeoVariant[Entity["HistoricalCountry", "HanDynasty"], "UnionArea"]]Dated restricts the historical entity to a specific date:
GeoDistance[Entity["HistoricalCountry", "RomanRepublic"], Dated[Entity["HistoricalCountry", "HanDynasty"], -200]]Dated can also be given with a date interval or a pair of dates or years:
GeoDistance[Entity["HistoricalCountry", "RomanRepublic"], Dated[Entity["HistoricalCountry", "HanDynasty"], {-200, -150}]]The distance between a historical entity and a non-historical entity is calculated using all territories:
GeoDistance[Entity["HistoricalCountry", "RomanEmpire"], Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}]]Dated can be used to restrict the polygons to a given date or interval:
GeoDistance[Dated[Entity["HistoricalCountry", "RomanEmpire"], 50], Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}]]Options (2)
DistanceFunction (1)
For extended entities, the distance is computed as the minimum between boundary points:
GeoDistance[Entity["AdministrativeDivision", {"Illinois", "UnitedStates"}], Entity["AdministrativeDivision", {"Florida", "UnitedStates"}], DistanceFunction -> "Boundary"]The distance between centers is larger:
GeoDistance[Entity["AdministrativeDivision", {"Illinois", "UnitedStates"}], Entity["AdministrativeDivision", {"Florida", "UnitedStates"}], DistanceFunction -> "Center"]When an entity is inside the other, a signed definition of distance can be used:
GeoDistance[Entity["AdministrativeDivision", {"Illinois", "UnitedStates"}], Entity["City", {"Champaign", "Illinois", "UnitedStates"}]]GeoDistance[Entity["AdministrativeDivision", {"Illinois", "UnitedStates"}], Entity["City", {"Champaign", "Illinois", "UnitedStates"}], DistanceFunction -> "SignedBoundary"]UnitSystem (1)
The default unit of the result is determined by the value of $UnitSystem:
$UnitSystemGeoDistance[Entity["City", {"NewYork", "NewYork", "UnitedStates"}], Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}]]GeoDistance[Entity["City", {"NewYork", "NewYork", "UnitedStates"}], Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}], UnitSystem -> "Metric"]Applications (2)
Compute the distances from your location to all US state capital cities:
USstateCapitals = EntityClass["AdministrativeDivision", "AllUSStatesPlusDC"]["CapitalCity"]dists = GeoDistance[Here, USstateCapitals]Find the minimum, maximum and mean distances:
MinMax[dists]Mean[dists]Plot a histogram of all those distances:
Histogram[dists, 20, PlotRange -> All]Draw a Mercator map of all geodesics from your location to the US capital cities:
GeoGraphics[GeoPath[{Here, #}]& /@ USstateCapitals, GeoProjection -> "Mercator"]A nautical mile was traditionally defined as the distance corresponding to a minute of arc of a meridian:
nauticMile[lat_] := GeoDistance[{lat - 1 / 120, 0}, {lat + 1 / 120, 0}]Plot[nauticMile[lat], {lat, 0, 90}, TargetUnits -> "Meters"]The standard "NauticalMiles" unit approximates the value at latitude 45 degrees:
UnitConvert["NauticalMiles", "Meters"]UnitConvert[nauticMile[45], "Meters"]Properties & Relations (10)
GeoDistance is a symmetric function:
p = GeoPosition[{30, 40}];
q = GeoPosition[{-40, 120}];GeoDistance[p, q]GeoDistance[q, p]GeoDistance is a partial inverse of GeoDestination:
GeoDestination[GeoPosition[{30, 40}], {10 ^ 6, 135}]GeoDistance[GeoPosition[{30, 40}], %, UnitSystem -> "Metric"]GeoDistance returns part of the result returned by GeoDisplacement for point-like locations:
p = Entity["City", {"Oslo", "Oslo", "Norway"}];
q = Entity["City", {"BuenosAires", "BuenosAires", "Argentina"}];GeoDistance[p, q, UnitSystem -> "SIBase"]GeoDisplacement[p, q]The length of a degree of parallel strongly depends on latitude:
GeoDistance[{10, 0}, {10, 1}]GeoDistance[{80, 0}, {80, 1}]But the length of a degree of meridian is approximately constant:
GeoDistance[{10, 0}, {11, 0}]GeoDistance[{80, 0}, {81, 0}]The distance corresponding to a given meridian angle α increases when approaching the poles:
α = 1;Plot[QuantityMagnitude@GeoDistance[{lat - α / 2, 0}, {lat + α / 2, 0}], {lat, -90 + α / 2, 90 - α / 2}]Compute distances between consecutive pairs in a list of points with GeoDistanceList:
points = {{-20, 10}, {40, 20}, {-23, 45}, {82, -132}};GeoDistanceList[points]//NormalThe same result can be obtained using Partition and GeoDistance, though in a less efficient way:
GeoDistance@@@Partition[points, 2, 1]Include the distance between the last and first point:
GeoDistance@@@Partition[points, 2, 1, 1]GeoDistance computes distances between points:
points = {{-20, 10}, {40, 20}, {-23, 45}, {82, -132}};GeoDistance[points]GeoLength computes the length of a geo path:
GeoLength[GeoPath[points]]Construct points on a geodesic circle, starting with regular bearings:
points = First@GeoDestination[{70, 0}, {1000000, Range[0, 360, 30]}]On an ellipsoid, they are not exactly equidistant:
GeoDistance@@@Partition[points, 2, 1]Differences[%]Construct multiple points along a geodesic, at regular distance intervals:
points = First@GeoDestination[{70, 0}, {Range[0, 1000000, 100000], 90}]GeoDistance@@@Partition[points, 2, 1]The list of distances can also be obtained with GeoDistanceList:
% == GeoDistanceList[points]The distance between two locations coincides with the distance between their antipodal locations:
p = GeoPosition[{35.1, 75.7}];
q = GeoPosition[{60.4, 130.9}];GeoDistance[p, q]GeoDistance[GeoAntipode[p], GeoAntipode[q]]Possible Issues (2)
Distance between extended geo entities is computed between boundaries by default, and hence zero for contiguous entities:
GeoDistance[Entity["Country", "Mexico"], Entity["Country", "UnitedStates"]]GeoDistance[Entity["Country", "UnitedStates"], Entity["Country", "Canada"]]Therefore, this total distance is also zero:
GeoDistance[{Entity["Country", "Mexico"], Entity["Country", "UnitedStates"], Entity["Country", "Canada"]}]The GeoDistance of two historical entities that do not coexist in time returns unevaluated:
GeoDistance[Entity["HistoricalCountry", "RomanRepublic"], Entity["HistoricalCountry", "Prussia"]]History
Introduced in 2008 (7.0) | Updated in 2014 (10.0) ▪ 2016 (10.4) ▪ 2024 (14.1)
Text
Wolfram Research (2008), GeoDistance, Wolfram Language function, https://reference.wolfram.com/language/ref/GeoDistance.html (updated 2024).
CMS
Wolfram Language. 2008. "GeoDistance." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/GeoDistance.html.
APA
Wolfram Language. (2008). GeoDistance. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GeoDistance.html
BibTeX
@misc{reference.wolfram_2026_geodistance, author="Wolfram Research", title="{GeoDistance}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/GeoDistance.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_geodistance, organization={Wolfram Research}, title={GeoDistance}, year={2024}, url={https://reference.wolfram.com/language/ref/GeoDistance.html}, note=[Accessed: 13-June-2026]}