I'm trying to display OpenCycleMaps inside google maps sdk for android using addTileOverlay
and a custom tile provider but its not working in the latest version of the SDK.
This is the version of the SDK I'm using -
com.google.android.gms:play-services-maps:17.0.0
And this is the code I'm using to display custom tiles. Here I'm setting the map to none and then showing custom tiles instead -
val SYDNEY = LatLng(-33.862, 151.21)
val ZOOM_LEVEL = 13f
override fun onMapReady(googleMap: GoogleMap?) {
googleMap ?: return
with(googleMap) {
moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, ZOOM_LEVEL))
addMarker(MarkerOptions().position(SYDNEY))
mapType = GoogleMap.MAP_TYPE_NONE
val mTileProvider = MyUrlTileProvider(256, 256, "http://a.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png")
addTileOverlay(TileOverlayOptions().tileProvider(mTileProvider))
}
}
This is the custom tile provider class -
class MyUrlTileProvider(width: Int, height: Int, private val baseUrl: String) : UrlTileProvider(width, height) {
override fun getTileUrl(x: Int, y: Int, zoom: Int): URL? {
try {
return URL(baseUrl.replace("{z}", "" + zoom).replace("{x}", "" + x).replace("{y}", "" + y))
} catch (e: MalformedURLException) {
e.printStackTrace()
}
return null
}
}
To make sure the problem was not in my code, I tried the same with this^ code in https://github.com/googlemaps/android-samples/tree/master/ApiDemos/kotlin and since they have not upgraded to androidX and are still using play-services-maps:11.8.0
it was working on there; custom tiles were being displayed. On upgrading that same code to use the latest maps SDK it stopped working.