我在Google地图上设置了自定义叠加层,以获取我的建筑物的室内地图。但是当我在屏幕上移动地图时,建筑物正在移动并且覆盖层是固定的。所以它有点难看。您可以在下面的图片中看到它有多丑。
我想得到这样的地图:pretty indoor map
如何防止建筑物在Android Google Maps API上移动?
在我用于在地图上设置叠加层的代码部分下面:
private GoogleMap mMap;
private MapView mapView;
@Override
public void onMapReady(GoogleMap googleMap) {
this.mMap = googleMap;
refreshGoogleMap();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
private void refreshGoogleMap() {
mMap.clear();
mMap.addTileOverlay(new TileOverlayOptions()
.tileProvider(new AssetsTileProvider())
.zIndex(-1));
}
private class AssetsTileProvider implements TileProvider {
private static final int TILE_WIDTH = 256;
private static final int TILE_HEIGHT = 256;
private static final int BUFFER_SIZE = 16 * 1024;
@Override
public Tile getTile(int x, int y, int zoom) {
byte[] bytes = readFile(x, y, zoom);
return bytes == null ? NO_TILE : new Tile(TILE_WIDTH, TILE_HEIGHT, bytes);
}
private byte[] readFile(int x, int y, int zoom) {
InputStream in = null;
ByteArrayOutputStream buffer = null;
try {
in = getAssets().open(getFilename(x, y, zoom));
buffer = new ByteArrayOutputStream();
int read;
byte[] data = new byte[BUFFER_SIZE];
while ((read = in.read(data, 0, BUFFER_SIZE)) != -1) {
buffer.write(data, 0, read);
}
buffer.flush();
return buffer.toByteArray();
} catch (Exception e) {
// NO OP
} finally {
if (in != null) try { in.close(); } catch (Exception ignored) {}
if (buffer != null) try { buffer.close(); } catch (Exception ignored) {}
}
return null;
}
private String getFilename(int x, int y, int zoom) {
String level = currentLevel == LEVEL_1 ? "level-1" : "level-2";
return level + "/" + zoom + "/" + x + "/" + y + ".png";
}
}