Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Adjusting the Starting Location and Zoom Level

00:00 In this lesson, you’ll learn how to adjust the starting location and zoom level of your Folium map.

00:07 Sometimes you’ll want to use Folium to create maps of the entire world, but other times, you’ll likely have data for one specific region. You can use the location parameter of your Folium map to center your map about one particular geolocation. To do so, just pass the tuple of latitude/longitude coordinates to location.

00:30 For example, let’s say you want to make a map that’s focused on New York City. You look up NYC’s coordinates and find it to be at approximately 40.7 degrees north, 74 degrees west.

00:44 Add the location parameter to your map, and let’s say you pass the tuple (40.7, 74).

00:52 That doesn’t look like New York City. Let’s zoom out a little. This is Kyrgystan, definitely not New York. So what happened here? When using the location parameter, be sure to pass a tuple that represents northing, easting coordinates.

01:09 New York is at 74 degrees west, so you’ll need to convert that to -74 degrees east for Folium.

01:19 Great. There’s NYC. Also notice that because you passed a location to your map, Folium has automatically zoomed in to focus on that region instead of showing the entire globe.

01:32 If you’d like to specify exactly how far to zoom in or out, you can update the zoom_start parameter. The zoom_start parameter controls the starting zoom level of your map.

01:45 Smaller zoom_start values begin with your map from a wider vantage point, while larger numbers zoom in more. For example, setting zoom_start equal to 1 gives you a map that’s too zoomed out and actually repeats the continents.

02:02 So let’s increase that to 5. This map is still centered about New York City, so now we see the northeast region of the United States. At level 10, we’re really focused on the city, and by 15, we have specific neighborhoods of New York, like Chelsea and the Meatpacking District.

02:22 Note that you can still zoom in and out of this map with the + buttons or by scrolling with your mouse.

02:30 You’ve just set the starting zoom level for your end user. And also keep in mind that the appropriate zoom_start level will also depend on your screen size, so feel free to continue experimenting until you have a setting that fits your particular need. Once you’ve found settings that work for you, you can save your map as a Python variable and then as an HTML file.

02:54 When you open that file, you or your end user will be presented with a map that starts from your predefined starting location and zoom level.

03:06 You now know how to focus your Folium map on a specific region by adjusting its geolocation and zoom. Up next, you’ll learn how to add geographic boundaries to your map by layering in data from a GeoJSON file.

Become a Member to join the conversation.