Maps aren't just for single points; we can also connect points together to draw routes, flight paths, borders, or regions!
The function drawtrail(lat_array, long_array) takes two matching Lua arrays (tables) of latitude and longitude coordinates and draws a polyline connecting them in sequence.
One famous geometric region on Earth is the mythical Bermuda Triangle in the western North Atlantic Ocean. Its vertices connect three famous points:
1. Miami, Florida ($25.7617^\circ\text{ N}, -80.1918^\circ\text{ W}$)
2. Bermuda ($32.3078^\circ\text{ N}, -64.7505^\circ\text{ W}$)
3. San Juan, Puerto Rico ($18.4655^\circ\text{ N}, -66.1057^\circ\text{ W}$)
To close the triangle back into a complete polygon, we repeat the first point (Miami) at the very end of the arrays!
drawtrail(lat_array,long_array)
Move the mouse over a dotted box for more information.
Both arrays must have the exact same number of elements. drawtrail automatically fits the map bounds so the entire path is visible!
Now you try. Try adding setmaptype("satellite") before drawing the trail to see how the triangle looks over the open ocean from space!
Type your code here:
See your results here:
To complete this lesson:
1. In the lats array, replace 0 with the latitude for San Juan: 18.4655.
2. In the longs array, replace 0 with the longitude for San Juan: -66.1057.
3. Click Run to draw the Bermuda Triangle path across the Atlantic Ocean!
Share your code
Show a friend, family member, or teacher what you've done!