Search code examples
javajavafxopenstreetmap

Why my custom JavaFX MapView request obtain 403 error by OSM?


I develop a custom MapView for a commercial sofware in JavaFX. Since only one week, all my request failed with 403 code error (exemple) :

"Server returned HTTP response code: 403 for URL: http://tile.openstreetmap.org/9/245/206.png"

But request success with browser like Mozilla. I haven't change some code or configuration, just OSM black-listed me.

However, I think, I'm following the osm policy rules, like only 2 connections in same times, memory cache system, not downloading huge area with high zoom.

How can legaly acces to OSM tiles on distributed software for commercial usage ? Usurpt Mozilla User-Agent can be a immediat solution during developpement but after ?

   private void loadImage(Tile tile) {
      String url = tile.getRetriever().computeURL(tile);
      if(!waiters.contains(url)) {
        waiters.add(url);
        threadPool.execute(new ComparableRunnable(url,()->{

            try {
                if(!exist(tile)) {

                    Semaphore semaphore = new Semaphore(1);
                    semaphore.acquire();

                    Image image = new Image(url, true);

                    image.errorProperty().addListener((obs,old,val)->{
                        if(image.isError()) {
                            Outil.loggerConsole(image.getException());
                            semaphore.release();
                        }
                    });
                } catch (InterruptedException e) {
                    Outil.loggerConsole(e);
                }
            }));

"Server returned HTTP response code: 403 for URL: http://tile.openstreetmap.org/9/245/206.png"


Solution

  • How can legaly acces to OSM tiles on distributed software for commercial usage ?

    By using a third-party provider or by running your own tile server. OSM's tile servers are not for commercial usage. See the Tile Usage Policy. Quoting the interesting parts:

    OpenStreetMap’s own servers are run entirely on donated resources. They have strictly limited capacity.

    [...]

    OpenStreetMap data is free for everyone to use. Our tile servers are not.

    [...]

    Heavy use (e.g. distributing an app that uses tiles from openstreetmap.org) is forbidden without prior permission from the System Administrators.

    See Alternative OpenStreetMap Tile Providers for solutions.