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 1


countries = EntityList@EntityClass["Country", "Europe"];

capitals = #["CapitalCity"] & /@ countries;

   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}}]

enter image description here enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.