Travel Time & Distance
Estimate distance and duration of a road trip.
Travel between two distant cities.
In[1]:=
![Click for copyable input](assets.en/travel-time-and-distance/In_42.png)
cities = {Entity["City", {"Lisbon", "Lisboa", "Portugal"}],
Entity["City", {"Beijing", "Beijing", "China"}]};
This is the geodesic distance between them.
In[2]:=
![Click for copyable input](assets.en/travel-time-and-distance/In_43.png)
GeoDistance[cities]
Out[2]=
![](assets.en/travel-time-and-distance/O_32.png)
This is the length of the computed road trip.
In[3]:=
![Click for copyable input](assets.en/travel-time-and-distance/In_44.png)
TravelDistance[cities]
Out[3]=
![](assets.en/travel-time-and-distance/O_33.png)
And this is the estimated driving time, assuming continuous driving with no stops.
In[4]:=
![Click for copyable input](assets.en/travel-time-and-distance/In_45.png)
TravelTime[cities]
Out[4]=
![](assets.en/travel-time-and-distance/O_34.png)
This object contains the actual set of travel instructions.
In[5]:=
![Click for copyable input](assets.en/travel-time-and-distance/In_46.png)
td = TravelDirections[{Entity[
"City", {"Lisbon", "Lisboa", "Portugal"}],
Entity["City", {"Beijing", "Beijing", "China"}]}]
Out[5]=
![](assets.en/travel-time-and-distance/O_35.png)
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](assets.en/travel-time-and-distance/In_47.png)
GeoGraphics[{Thick, Red, GeoPath[td], Blue,
GeoPath[{Entity["City", {"Lisbon", "Lisboa", "Portugal"}],
Entity["City", {"Beijing", "Beijing", "China"}]}]},
GeoProjection -> "Mercator", GeoGridLines -> Automatic]
Out[6]=
![](assets.en/travel-time-and-distance/O_36.png)
An azimuthal projection shows more clearly that the geodesic is shorter than the travel path.
In[7]:=
![Click for copyable input](assets.en/travel-time-and-distance/In_48.png)
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]=
![](assets.en/travel-time-and-distance/O_37.png)