I need help calculating the distance between 2 cities in Wolfram MAthematica. I would need to create two drop-down lists of European capitals. After selecting any two cities from the lists, I would need to calculate the distance between these cities. I tried using GeoDistance, but I can't use it for two city lists. Thank you very much for your help ! Thera
1 Answer
$\begingroup$
$\endgroup$
Clear["Global`*"]
countries = EntityList@EntityClass["Country", "Europe"];
capitals = #["CapitalCity"] & /@ countries;
Manipulate[
Column[{
distance[start, end, UnitSystem -> units],
GeoGraphics[{Red, Thick,
Polygon[countries[[Position[capitals, start][[1, 1]]]]],
Polygon[countries[[Position[capitals, end][[1, 1]]]]],
If[distance === GeoDistance,
GeoPath[{start, end}],
Line[TravelDirections[{start, end}]]]},
ImageSize -> Medium]}],
{{start, capitals[[-2]]},
Thread[capitals ->
(Last /@ capitals)[[All, {1, 3}]]]},
{{end, capitals[[18]]},
Thread[capitals ->
(Last /@ capitals)[[All, {1, 3}]]]},
{{units, "Metric"}, {"Metric", "Imperial"}},
{{distance, GeoDistance}, {GeoDistance, TravelDistance}}]