implementation 'org.osmdroid:osmdroid-android:6.1.10'
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
tilesource="Mapnik"
/>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val map = findViewById<MapView>(R.id.map)
map.setTileSource(TileSourceFactory.MAPNIK)
map.setMultiTouchControls(true)
}
val osmUrl = "https://www.openstreetmap.org/relation/{relationID}"
val relationId = 12345 // Replace with actual relation ID
val osmParser = OsmParser(osmUrl.replace("{relationID}", relationId.toString()), applicationContext)
val mapView = findViewById<MapView>(R.id.map)
osmParser.load(mapView)
osmParser.onLoadComplete = {
// Add markers, lines, or other map features using the MapView's Overlays
val startPoint = GeoPoint(40.748817, -73.985428) // Example location in New York City
val marker = Marker(mapView)
marker.position = startPoint
mapView.overlays.add(marker)
mapView.invalidate()
}
That's it! Your app should now display the OSM data for the specified Relation ID.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-20 10:40:55 +0000
Seen: 19 times
Last updated: Jul 20 '23
Why can't IntelliJ IDEA detect the Kotlin multiplatform library?
What is the correlation between coroutines and the Kotlin Gradle Plugin?
What are the typical approaches found in a Gradle build script?
Why isn't the date picker dialog displayed in an Android fragment using Kotlin in Android Studio?
What is the meaning of the error message "Task :react-native-gradle-plugin:compileKotlin FAILED"?
Is it necessary to have an updated Kotlin Gradle plugin for your project?
How can we avoid the duplication of Kotlin class jetified-kotlin-stdlib-1.8.10 in Android (Java)?
What is the process to integrate SQLiter in KMM for both Android and IOS?
Can a transitive dependency in gradle be made exclusively for runtime purposes?