I'm trying to plot a map with a list of destinations as Disks.

I first input the cities into a list such as:

destinations = {GeoPosition[New York City],

where "New York City" is input using the Ctrl+= method to access interpreter and specify it as a city.

Then I have something summarizing to:

Disk[For[i=1, i<Length[destinations]+1,i++,destinations[[i]],1],

This outputs a map with my desired projection settings such as background, range, and the single disk that I specified separately like:


I have also tried to put the Disk function inside a for loop like:

For[i=1, i<Length[destinations]+1,i++,Disk[destinations[[i]],1]],

It's not an incorrect indexing of the destinations list either, because

For[i=1, i<Length[destinations]+1,i++,Print[destinations[[i]]]]

outputs the correct amount of cities, whereas

For[i=0, i<Length[destinations],i++,Print[destinations[[i]]]]

outputs a first item of "List" and doesn't print the last city.

Is it possible to use for loops within a GeoGraphics function, or would I be required to add a Disk function line for each item I would like to plot instead of iterating through a list?

Thanks in advance for the help!


1 Answer 1


You don't need For loops.

Instead you can Map Disk on destinations; that is, use Disk /@ destinations (Disk[#, 5]& /@ destinations if you want a radius of 5 instead of the default radius 1).

cities = {Entity["City", {"NewYork", "NewYork", "UnitedStates"}], 
    Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}], 
    Entity["City", {"Bombay", "Maharashtra", "India"}], 
    Entity["City", {"Delhi", "Delhi", "India"}]};
destinations = GeoPosition /@ cities;

GeoGraphics[{Black, Disk /@ destinations}]

enter image description here

Notes: If you have to use a For loop you can do:

disks = {}; 
For[i = 1, i <= Length[destinations], i++, AppendTo[disks, Disk[destinations[[i]]]]];
GeoGraphics[{Black, disks}]

same picture

Alternatively, you can use Table:

Table[Disk[i], {i, destinations}] == disks


and if you have to use a For loop inside GeoGraphics

GeoGraphics[{Black, disks = {}; 
  For[i = 1, i <= Length[destinations], i++, 
   AppendTo[disks, Disk[destinations[[i]]]]]; disks}]

same picture

  • $\begingroup$ Yes, this works perfectly thank you! $\endgroup$ Nov 29, 2018 at 22:07

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.