1
我成立了一個自定義UrlTileProvider
呈現在MapsActivity
瓦片如下:定製瓷磚不上GoogleMap的地圖顯示
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
if (mMap == null) {
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
TileProvider tileProvider = new CustomTileProvider();
TileOverlayOptions tileOverlayOptions = new TileOverlayOptions()
.tileProvider(tileProvider);
tileOverlayOptions.visible(true);
tileOverlayOptions.zIndex(10000);
TileOverlay tileOverlay = mMap.addTileOverlay(tileOverlayOptions);
}
}
..
public class CustomTileProvider extends UrlTileProvider {
private static final int TILE_WIDTH = 256;
private static final int TILE_HEIGHT = 256;
private static final int MIN_ZOOM = 12;
private static final int MAX_ZOOM = 16;
private static final String TILE_SERVER_URL = ...
public CustomTileProvider() {
this(TILE_WIDTH, TILE_HEIGHT);
}
public CustomTileProvider(final int width, final int height) {
super(width, height);
}
@Override
public URL getTileUrl(int x, int y, int zoom) {
String tileServerUrl = String.format(TILE_SERVER_URL, zoom, x, y);
if (!checkTileExists(x, y, zoom)) {
return null;
}
try {
return new URL(tileServerUrl);
} catch (MalformedURLException exception) {
throw new AssertionError(exception);
}
}
private boolean checkTileExists(int x, int y, int zoom) {
if ((zoom < MIN_ZOOM || zoom > MAX_ZOOM)) {
return false;
}
return true;
}
}
這是基本相同的,其能被發現在Google documentation。
由於某種原因,服務器提供的區域不顯示任何圖塊。從未調用方法getTileUrl()
。
如果您不想爲某些縮放級別或x/y座標提供拼貼,則應該返回TileProvider.NO_TILE而不是null。如果您絕對確信,該方法從未被調用,那當然不會解決您的問題。 – user2808624 2014-10-02 14:41:20
'抽象'類'UrlTileProvider'需要實現'public abstract java.net.URL getTileUrl(int i,int i1,int i2);' – JJD 2014-10-02 15:10:54