Kotlin中的Google Maps Tile图层

问题描述 投票:0回答:2

我正在尝试使用谷歌地图SDK Android实现Tile Layers,但官方文档只有Java代码示例,我的项目在Kotlin。我找不到任何关于如何在kotlin中做同样的例子。谁知道怎么做?

The documentation java example code

private GoogleMap mMap;

TileProvider tileProvider = new UrlTileProvider(256, 256) {
  @Override
  public URL getTileUrl(int x, int y, int zoom) {

    /* Define the URL pattern for the tile images */
    String s = String.format("http://my.image.server/images/%d/%d/%d.png",
        zoom, x, y);

    if (!checkTileExists(x, y, zoom)) {
      return null;
    }

    try {
      return new URL(s);
    } catch (MalformedURLException e) {
        throw new AssertionError(e);
    }
  }

  /*
   * Check that the tile server supports the requested x, y and zoom.
   * Complete this stub according to the tile range you support.
   * If you support a limited range of tiles at different zoom levels, then you
   * need to define the supported x, y range at each zoom level.
   */
  private boolean checkTileExists(int x, int y, int zoom) {
    int minZoom = 12;
    int maxZoom = 16;

    if ((zoom < minZoom || zoom > maxZoom)) {
      return false;
    }

    return true;
  }
};

TileOverlay tileOverlay = mMap.addTileOverlay(new TileOverlayOptions()
    .tileProvider(tileProvider));

任何帮助都将不胜感激

android google-maps kotlin google-maps-android-api-2
2个回答
0
投票

最后我最终自己做了qazxsw poi,我只需要像这样实例化qazxsw poi抽象类:

based in this response

最终结果:

UrlTileProvider

希望它能帮助别人。


0
投票

在这里你干杯!

val tileProvider: TileProvider = object: UrlTileProvider(256, 256){ 
...
}
© www.soinside.com 2019 - 2024. All rights reserved.