O'Reilly logo

Google Maps JavaScript API Cookbook by Balkan Uraz, Alper Dincer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Restricting the map extent

Google Maps has a worldwide extent that shows almost every street on the earth. You can use the Google Maps JavaScript API for the whole earth, but sometimes you need to show only the related area in the mapping application. You can zoom to a fixed location, but this doesn't stop users from moving to another place that is not in the extent of your application.

In this recipe, we will listen for map events to check if we are in an allowed extent. If we are not in the allowed extent, then we move the map to the allowed center within the extent. We used Turkey's geographic extent in this recipe.

Getting ready

This recipe is still using the same map creation process defined in Chapter 1, Google Maps JavaScript API Basics, but ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required