Once you have drawn a map, you usually want to highlight specific locations. On digital maps, this is done using markers (or map pins).
We have a built-in function to drop markers on your OpenStreetMap:
setmarker(latitude, longitude, "title")
The first two arguments specify the exact coordinates of the pin, and the third argument is a text label that pops up when you click the marker.
In this lesson, we will explore New York Harbor, centering our map near Liberty Island and dropping markers on iconic landmarks like the Statue of Liberty ($40.6892^\circ\text{ N}, -74.0445^\circ\text{ W}$) and Ellis Island ($40.6995^\circ\text{ N}, -74.0397^\circ\text{ W}$).
setmarker(latitude,longitude,"title")
Move the mouse over a dotted box for more information.
You can place as many markers as you want on a single map! Each marker will display its own label when clicked.
Now you try. Try adding a third marker for the Empire State Building at Latitude 40.7484, Longitude -73.9857 (you might need to adjust the map zoom or center to see it!).
Type your code here:
See your results here:
To complete this lesson:
1. Look at the second setmarker call currently set to (0, 0, "Ellis Island").
2. Replace 0, 0 with the coordinates for Ellis Island: 40.6995, -74.0397.
3. Click Run to see both markers placed in New York Harbor. Click each marker pin to see its popup label!
Share your code
Show a friend, family member, or teacher what you've done!