Keep tiles visible while loading TileOverlay Map API v2 Android

别来无恙 提交于 2019-12-21 03:22:08

问题


I would like my TileOverlay to behave like the real Google Maps. When you zoom in, the tile is still visible but pixelized until the new tile is downloaded.

The current behavior is: when you zoom in, tiles disappear and you see the ugly grid, and the user has to wait until the new tiles are loaded. This is kind of annoying.

Is there a solution to this problem?


回答1:


I worked around this issue by "preloading" all zoomlevels before showing the map (just a copy/paste of the current state, need to clean up):

@UiThread
private void preloadAllZoomLevels(final float zoomLevel) {
    if (zoomLevel == map.getMaxZoomLevel()) {
        map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 7));
        mapFragmentContainer.animate().alpha(1f);
        return;
    }
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), zoomLevel));

    final float nextZoomLevel = zoomLevel + 1;
    map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            preloadAllZoomLevels(nextZoomLevel);
        }
    });
}



回答2:


Essentially, every time GoogleMap wants to draw tile for specific coordinate - it asks you to provide this tile. You can use either static tile (see TileProvider) or you can provide URL, so GoogleMap goes to your web server and downloads this tile automatically (see UrlTileProvider)

Don't know is it work for you! But you can share details about your requirements if it's not working. Thanks



来源:https://stackoverflow.com/questions/17911506/keep-tiles-visible-while-loading-tileoverlay-map-api-v2-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!