I’m new here, I’m working on a small gps game that display a simple map.
I’m using Kotlin with osmdroid 6.1.18
I successfully displayed a map with MAPNIK as tile source :
MapView.setTileSource(TileSourceFactory.MAPNIK)
MAPNIK map
However, this map display too much information for people to play with.
I want to display a map with only roads and paths (maybe their names, but that’s all !).
So I tried to display other tile sourced maps : HIKEBIKEMAP, OPEN_SEAMAP, PUBLIC_TRANSPORT, etc …
But all of them are blank :
Blank map
I searched in the small FAQ from the GitHub and tried every solutions related to my problem :
- setting the “user agent”
- creating a “network_security_config.xml”
- checking permissions in “AndroidManifest.xml”
But it didn’t change a thing.
So I tried to use the Debug mode from Configuration.getInstance().isDebugMode = true
but I’m drowning from the amount of information I get in the Logcat. I don’t know what error is related to my map problem.
I stopped searching with the debug mode and focused on setting the TileSource through URLs like this. But the map still blank, even if I tried different URLs recommended in other stackoverflow’s solutions.
I doubt the URLs links are broken.
I’m out of options and kinda lost, so I’m asking help for just displaying a simplier map !
Here’s my MainActivity :
class MainActivity : ComponentActivity() {
private val REQUEST_PERMISSIONS_REQUEST_CODE = 1
private lateinit var map : MapView
private lateinit var text : TextView
private lateinit var mapController : IMapController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Configuration.getInstance().apply {
userAgentValue = applicationContext.packageName
load( applicationContext, PreferenceManager.getDefaultSharedPreferences(applicationContext))
// isDebugMode = true // DEBUG
}
setContentView(R.layout.activity_main)
// DEBUG TextView
//text = findViewById(R.id.debugText)
//Configuration.getInstance().apply {
// text.append("cacheMapTileCount : $cacheMapTileCountn" +
// "cacheMapTileOvershoot : $cacheMapTileOvershootn")
//}
// TILES
val tileSource: ITileSource = XYTileSource(
"HOT", 1, 20, 256, ".png", arrayOf(
"http://a.tile.openstreetmap.fr/",
"http://b.tile.openstreetmap.fr/",
"http://c.tile.openstreetmap.fr/"
), "© OpenStreetMap contributors"
)
// Map creation from Tiles
map = findViewById(R.id.map)
map.apply {
setTileSource(tileSource)
setBuiltInZoomControls(true)
overlayManager
}
// Start from this point
val startPoint = GeoPoint(47.9, 1.9)
mapController = map.controller
mapController.setZoom(18.0)
mapController.setCenter(startPoint)
// Display my location
// val mLocationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(applicationContext), map)
// mLocationOverlay.enableMyLocation()
// map.overlays.add(mLocationOverlay)
// Display a compass
// val compassOverlay = CompassOverlay(applicationContext, InternalCompassOrientationProvider(applicationContext), map)
// compassOverlay.enableCompass()
// map.overlays.add(compassOverlay)
// Display lonlat grid
//val overlay = LatLonGridlineOverlay2()
//map.overlays.add(overlay)
// Add map rotation
// val rotationGestureOverlay = RotationGestureOverlay(map)
// rotationGestureOverlay.isEnabled
// map.setMultiTouchControls(true)
// map.overlays.add(rotationGestureOverlay)
// Interest point creation
// var items = mutableListOf<OverlayItem>()
// var origin = OverlayItem("Statue de Jeanne d'Arc","Héroïne d'Orléans", GeoPoint(47.8,2.0))
//var draw : Drawable = origin.getMarker(0)
// items.add(origin)
// items.add(OverlayItem("3030","Random", GeoPoint(0.1,0.1)))
// Map listener
// val listener = object : OnItemGestureListener<OverlayItem> {
// override fun onItemSingleTapUp(index : Int, item : OverlayItem): Boolean {
// println("MAP : onItemSingleTapUp") // DEBUG
// return true
// }
// override fun onItemLongPress(index : Int, item : OverlayItem): Boolean {
// println("MAP : onItemLongPress") // DEBUG
// return false
// }
// }
// var mOverlay = ItemizedOverlayWithFocus(applicationContext, items, listener)
// mOverlay.setFocusItemsOnTap(true)
// map.overlays.add(mOverlay)
// Inside your activity
/*if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted, request it
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
MY_PERMISSIONS_REQUEST_LOCATION
)
}*/
}
override fun onPause() {
super.onPause()
map.onPause()
println("MAP : onPause") // DEBUG
}
override fun onResume() {
super.onResume()
map.onResume()
println("MAP : onResume") // DEBUG
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
val permissionsToRequest = ArrayList<String>()
var i = 0
while (i < grantResults.size) {
permissionsToRequest.add(permissions[i])
i++
}
if (permissionsToRequest.size > 0) {
ActivityCompat.requestPermissions(
this,
permissionsToRequest.toTypedArray(),
REQUEST_PERMISSIONS_REQUEST_CODE)
}
}
}
My permissions from “AndroidManifest” :
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.location.network" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.wifi" />
Thanks all in advance for reading and answering, if you need more information do not hesitate.
Dagflot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.