Search code examples
androidosmdroid

Loading Open Cycle Map on OSMdroid


Sorry I am new to Android development. Wondering if there is any method to load Open Cycle Map using OSMdroid please? From the website, seems there is no easy way to do so: https://github.com/osmdroid/osmdroid/wiki/Map-Sources

Therefore, would any one can give me some tips how to do so please?

What I can think the only way is to define Tile Source manually as below. Wondering if there is any easier way to do so please?

final String[] tileURLs = {"http://a.tile.thunderforest.com/cycle/",
              "http://b.tile.thunderforest.com/cycle/",                                              
               "http://c.tile.thunderforest.com/cycle/"};

final ITileSource OCM =
        new XYTileSource("Open Cycle Map",
                            0,
                            19,
                            512,
                            ".png",
                            tileUrls,
                            "from open cycle map");

Thanks a lot


Solution

  • Defining a tile-source is a correct way how to do it. And it's a perfectly fine way, many build-in tile-sources are defined in the same way.

    However, according to the documentation at the http://thunderforest.com/maps/opencyclemap/ you should obtain and use API key:

    Want to use these tiles? The generic tile format string for the OpenCycleMap layer is:

    https://tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey=<insert-your-apikey-here>

    Therefore you should include you API key:

    final ITileSource OCM =
            new XYTileSource("Open Cycle Map",
                                0,
                                19,
                                512,
                                ".png?apikey=<insert-your-apikey-here>",
                                tileUrls,
                                "from open cycle map");
    

    (This is just modified code from the question. I didn't test it and therefore some parameters don't have to be correct)