14

Leaflet is open source and free. However the examples on leaflet site use Mapbox to render map. Mapbox is more expensive than Google map (Mapbox pricing). The question is: can anyone use Leaflet really free?

Tony
  • 603
  • 5
  • 9
  • 17

1 Answers1

36

You can use the Leaflet library for free, only the tileprovider used in the examples, Mapbox, asks money for serving tiles. You just need a free tileprovider like OpenStreetMap for instance:

var map = new L.Map('leaflet', {
    center: [0, 0],
    zoom: 0,
    layers: [
        new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            'attribution': 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
        })
    ]
});
body {
    margin: 0;
}

html, body, #leaflet {
    height: 100%;
}
<!DOCTYPE html>
<html>
  <head>
    <title>Leaflet 1.0.3</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link type="text/css" rel="stylesheet" href="//unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
  </head>
  <body>
    <div id="leaflet"></div>
    <script type="application/javascript" src="//unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
  </body>
</html>
iH8
  • 27,722
  • 4
  • 67
  • 76
  • 2
    is using OSM tile completely free, i was just looking at this page - https://operations.osmfoundation.org/policies/tiles/ and looks like they say otherwise. – whyAto8 Jul 23 '20 at 12:56
  • 4
    To clarify - "Heavy use (e.g. distributing an app that uses tiles from openstreetmap.org) is forbidden without prior permission ... Alternative OpenStreetMap Tile Providers ..." – flywire Sep 16 '20 at 11:45