Wolfram Language

Geo Computation

Travel Time & Distance

Estimate distance and duration of a road trip.

Travel between two distant cities.

In[1]:=
Click for copyable input
cities = {Entity["City", {"Lisbon", "Lisboa", "Portugal"}], Entity["City", {"Beijing", "Beijing", "China"}]};

This is the geodesic distance between them.

In[2]:=
Click for copyable input
GeoDistance[cities]
Out[2]=

This is the length of the computed road trip.

In[3]:=
Click for copyable input
TravelDistance[cities]
Out[3]=

And this is the estimated driving time, assuming continuous driving with no stops.

In[4]:=
Click for copyable input
TravelTime[cities]
Out[4]=

This object contains the actual set of travel instructions.

In[5]:=
Click for copyable input
td = TravelDirections[{Entity[ "City", {"Lisbon", "Lisboa", "Portugal"}], Entity["City", {"Beijing", "Beijing", "China"}]}]
Out[5]=

Represent the trajectory (in red) on a Mercator map and compare with the geodesic trajectory (in blue), which is shorter, as you saw before.

In[6]:=
Click for copyable input
GeoGraphics[{Thick, Red, GeoPath[td], Blue, GeoPath[{Entity["City", {"Lisbon", "Lisboa", "Portugal"}], Entity["City", {"Beijing", "Beijing", "China"}]}]}, GeoProjection -> "Mercator", GeoGridLines -> Automatic]
Out[6]=

An azimuthal projection shows more clearly that the geodesic is shorter than the travel path.

In[7]:=
Click for copyable input
GeoGraphics[{Thick, Red, GeoPath[td], Blue, GeoPath[{Entity["City", {"Lisbon", "Lisboa", "Portugal"}], Entity["City", {"Beijing", "Beijing", "China"}]}]}, GeoProjection -> "Mercator", GeoGridLines -> Automatic]; Show[%, GeoProjection -> "LambertAzimuthal", GeoZoomLevel -> 4]
Out[7]=

Related Examples

de es fr ja ko pt-br ru zh