Reputation: 11
my code is below
mapView.setTileSource(new OnlineTileSourceBase("USGS Topo", 0, 18, 256, ".png",
new String[] { "https://maps.tilehosting.com/c/48533dee-0f32-42a2-a6db-315bbc7ecca8/styles/bdbasic/{z}/{x}/{y}.png?key=xxxxxxxxxx" }) {
@Override
public String getTileURLString(long pMapTileIndex) {
return getBaseUrl()
+ MapTileIndex.getZoom(pMapTileIndex)
+ "/" + MapTileIndex.getY(pMapTileIndex)
+ "/" + MapTileIndex.getX(pMapTileIndex)
+ mImageFilenameEnding;
}
});
https://github.com/osmdroid/osmdroid/wiki/Map-Sources
My Version is 6.0.3
Upvotes: 1
Views: 1629
Reputation: 271
Are you set user agent?
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IConfigurationProvider provider = Configuration.getInstance();
provider.setUserAgentValue(BuildConfig.APPLICATION_ID);
provider.setOsmdroidBasePath(getStorage());
provider.setOsmdroidTileCache(getStorage());
// provider.setDebugMapTileDownloader(true);
//provider.setDebugTileProviders(true);
setContentView(R.layout.osm_activity);
}
Upvotes: 1
Reputation: 5790
Pay attention to the string you copy pasted into your code:
https://maps.tilehosting.com/c/48533dee-0f32-42a2-a6db-315bbc7ecca8/styles/bdbasic/{z}/{x}/{y}.png?key=xxxxxxxxxx"
That's apparently some example from some documentation of your tile provider. {z},{x} and {y} are variables and must be dynamically added by osmdroid. And xxxxx shuld be replaced by your API key.
You should use only the base part in your code:
https://maps.tilehosting.com/c/48533dee-0f32-42a2-a6db-315bbc7ecca8/styles/bdbasic/
The rest of the URL is added in the getTileURLString
method. You have also a mistake there. As you can see in the example, the order of params should be z(zoom) x and y. You have x and y swapped in your code.
The example also hints that you should have some API key. So check the documentation of the tile provider again and obtain the key if neccessary. You can than pass the key via the parameter which now contains only ".png". You'll need to change it to ".png?key=yourkeyandnotthisstringorxxxxx".
In the end you should endup with something like this:
mapView.setTileSource(new OnlineTileSourceBase("USGS Topo", 0, 18, 256, ".png?key=yourkeyandnotthisstringorxxxxx",
new String[] { "https://maps.tilehosting.com/c/48533dee-0f32-42a2-a6db-315bbc7ecca8/styles/bdbasic/" }) {
@Override
public String getTileURLString(long pMapTileIndex) {
return getBaseUrl()
+ MapTileIndex.getZoom(pMapTileIndex)
+ "/" + MapTileIndex.getX(pMapTileIndex)
+ "/" + MapTileIndex.getY(pMapTileIndex)
+ mImageFilenameEnding;
}
});
Upvotes: 1