anko icon indicating copy to clipboard operation
anko copied to clipboard

Build a MapView

Open teawithfruit opened this issue 5 years ago • 2 comments

Hello.

I'm new to anko and I like the idea to write layouts without XML. So right now I'm trying to build my XML layouts with anko. At this moment the MapView, but it will not work. I got no error, but I also do not see the map. Reading the wiki didn't help me eather to get a solution. This is my current code:

class MapViewActivityUI : AnkoComponent<MapViewActivity> {

    val TAG = "MapViewActivityUI"

    inline fun ViewManager.mapView(init: MapView.() -> Unit = {}): MapView {
        return ankoView({ MapView(it) }, theme = 0, init = init)
    }

    override fun createView(ui: AnkoContext<MapViewActivity>) = with(ui) {
        constraintLayout {
            mapView() {
                getMapAsync { googleMap: GoogleMap ->
                    Log.d(TAG, "getMapAsync")
                    Log.d(TAG, googleMap.toString())
                }
            }.lparams(width = matchParent, height = matchParent)
        }
    }

}

What am I doing wrong?

It would be very nice, if someone with more expirience then me could give me a hint, how to create a MapView with anko.

Thanks!

teawithfruit avatar May 17 '19 16:05 teawithfruit

I have the same problem i don't know haw touse a Map with anko

louaydhyeb avatar May 29 '19 11:05 louaydhyeb

From https://github.com/Kotlin/anko/wiki/Anko-Layouts, you need to add this extension function to your code: inline fun ViewManager.mapView(init: MapView.() -> Unit = {}): MapView { return ankoView({ MapView(it) }, theme = 0, init = init) }

You should be then be able to add a mapView in the DSL: frameLayout { val myMapView = mapView().lparams(width = matchParent) }

Call myMapView.MapAsync() somewhere after the above.

eitzend avatar Jun 20 '19 01:06 eitzend