Home > database >  Osmdroid (open street map) marker slow to draw after click to map
Osmdroid (open street map) marker slow to draw after click to map

Time:07-12

I'm brand new to Open Street Map and have successfully added a map to my activity at the user's location and implemented an onClickListener that upon a click shows a marker and retrieves the latitude and longitude of that point. Here is my code

private fun showMap(dLatInit: Double, dLonInit: Double){
    mapView.setTileSource(TileSourceFactory.MAPNIK)
    Configuration.getInstance().userAgentValue =packageName
    mapView.setMultiTouchControls(true)
    mapController = mapView.controller as MapController
    mapController.setZoom(10.0)
    val pointCenter= GeoPoint(dLatInit, dLonInit)
    mapController.setCenter(pointCenter)

    val mReceive: MapEventsReceiver = object : MapEventsReceiver {
        override fun singleTapConfirmedHelper(geoPoint: GeoPoint): Boolean {
            Marker(mapView).apply {
                this.position = geoPoint
                this.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
                mapView.overlays.add(this)
            }
            populateEditText(textInputLayoutMapLat.editText, geoPoint.latitude.also { dMapLat =it })
            populateEditText(textInputLayoutMapLon.editText, geoPoint.longitude.also { dMapLon =it })
            return false
        }
        override fun longPressHelper(p: GeoPoint): Boolean {
            return false
        }
    }
    val overlayEvents = MapEventsOverlay(mReceive)
    mapView.overlays.add(overlayEvents)
}

It works. The latitude and longitude immediately populate, however the marker takes from 3-5 seconds to show on my map. I'd like the marker to show much quicker.

My dependency

implementation 'org.osmdroid:osmdroid-android:6.0.3'

CodePudding user response:

add

mapView.postInvalidate()

to force a redraw

  • Related