Tile generator from an image to Android Google Map

2019-05-03 20:54发布

问题:

This is my 1st question here, so lets move right to the point

I have a map in high resolution png format with geographic coordinates of the corners which I would like to integrate with Google Maps Api in my Android App.

What i have done so far:

  • I have cut the map in tiles 256x256 px and wrote an URITileProvider. It turns out that the map has an offset, is tilted and has to be re-sized

  • I found MapTiler and tried it out. It allows to set the corners coordinates and generates tiles. The current free version produces a watermark, so I have also checked the previous beta versions - but there the "y" tile coordinate is placed on the other hemisphere. Of course i could try to map them, but it doesn't solve my tilt problem

  • I also found and Android app CustomMaps. It is awesome! It does almost exactly what i want except it does not generate tiles. There is an option to take an image file, put it on the map by selecting points from the image and linking them to google map. It also provides a nice overview.

So here is my question:

Is there a free tool which combines both functionality form MapTiler and CustomMaps that I could use to align my image to map and split it into valid tiles?

I thought about editing the source image and by trial-and-error method, but it is definitely not the way to go here. Currently I'm thinking of creating my own tool, but logically thinking there has to be already a solution out there.

回答1:

I have managed to solve this problem and I've thought that I would share it with you. I wrote my own tile generator. The solution surely is not ideal and could need a lot more work. Any contributions are welcome.

Here are the steps to make it work:

  1. Use Google Maps, zoom in on the desired area, paste into graphic editing program as a background layer.
  2. Paste your overlay map into the graphic program on another layer and transform it to match the map in background
  3. Using Google maps read as precisely as possible the max/min latitude and longitude
  4. Use my MapTileGenerator to generate the tiles.
  5. In Android use URITileProvider

    @Override
    public URL getTileUrl(int x, int y, int zoom) {
    
        String url = MAP_FILES_URL + x + "-" + y + "-" + zoom + ".png";
        try {
            return new URL(url);
        } catch (MalformedURLException e) {
            // ignore
        }
        return null;
    }
    

I have recorded a short video for the process. It is available on youtube: Map Tile Generator Instructions. Unfortunately it is in polish, but the message should be pretty clear after reading the points above.

I am well aware that the script i wrote has problems with memory management and should use introduce multithreading. I hope i can get back to it any time soon.