Get "Shortest City Tours" on Australia?

I was trying this guide on Australia: Shortest City Tours: Wolfram Programming Lab Gallery

I did:

coords = EntityValue[GeoEntities[Entity["Country", "Australia"], "City"], "Coordinates"]
route = Last[FindShortestTour[coords]]
GeoGraphics[{Thick, Red, Line[coords[[route]]]}]

The result is in the attachment. As you can see, it’s above the map. What did I do wrong?

There is a bug in the example. Please report this to Wolfram so they can fix the website.

Should be GeoPath instead of Line.

GeoGraphics[{Thick, Red, GeoPath[coords[[route]]]}]

to get:

Line can work too… if in the original 1st line “Coordinates” are replaced with “Position”:

coords = EntityValue[GeoEntities[Entity["Country", "Australia"], "City"], "Position"]

LJ you should carefully examine the outputs your code produces and you would be able to figure out the issue. Something changed in syntax but there are still a work around so you can go further with your studies.

Cheers!

The underlying reason is that Line accepts x,y coordinates, while GeoPath accepts latitude longitude pairs (which is kinda y,x).
Can indeed be solved in many ways:

coords = EntityValue[GeoEntities[Entity["Country", "Australia"], "City"], "Coordinates"];
route = Last[FindShortestTour[coords]];
GeoGraphics[{Thick, Red, Line[Reverse /@ coords[[route]]]}]
GeoGraphics[{Thick, Red, Line[coords[[route, {2, 1}]]]}]
GeoGraphics[{Thick, Red, GeoPath[coords[[route]]]}]

Thanks guys! Changing it from Line to GeoPath works. As suggested, I reported it to Wolfram a few days ago, so hopefully it’ll be fixed soon. Thanks again :slight_smile:

Note that this is not a bug. It should be like you described in your original post. Coordinates are in the x,y form while GeoGraphics accepts Lat,Lon pairs (‘y’,‘x’).

Using Position with entityValue gives coordinates in the lat,lon format.

Sander,

You are correct. The bug I was referring to was not in Mathematica but a bug in the wolfram website example. The code as posted has the error because it tries to use line on Lat,Lon pairs.