Search code examples
leaflethttp-status-code-404

Max zoom are different on a different regions


On a land I can zoom up to 20 points, but on the sea/ocean I can only zoom up to 7-12 point (it depends which location you are zooming). If I zoom above 7-12 point on the ocean I see 404 errors in browser console (https://khms0.googleapis.com/kh?v=944&hl=en-GB&x=260660&y=177418&z=19) and when I reach 19 map becomes gray.

Is there a way to limit max zoom value depending on the coordinates you are standing and get rid of console errors?


Solution

  • You could use MaxZoomService available in the api to get the max zoom level api available in a certain area.

    This way you can follow this algorithm:

    1. Get current position
    2. Fetch the max zoom available in the current position through the google maps api
    3. Set it as the max zoom on leaflet
    4. Get the current zoom in in the map
    5. If currentZoom > maxZoom, then zoom out to the max zoom available