Warm tip: This article is reproduced from stackoverflow.com, please click
android google-maps kotlin

Android Google Maps no UI

发布于 2020-03-29 21:03:49

Replicating some behavior in an iOS app to Android and one of the requirements is to be able to generate a map snapshot. Google maps does offers the ability to create a snapshot of a map but unlike the iOS app I don't see a way of creating the map purely in memory and then saving it to a DB. I've created maps before but it was always done with the intent of showing the map and the user interacting with it. In this scenario I don't want any of that. There should be no map to be viewed at this point. At a later time the generated image (bitmap) from the snapshot will be delivered to the user.

I have the onMapReady function all set like so

override fun onMapReady(map: GoogleMap?) {

    map?.let {
        //add route
        it.addPolyline(routeLines)

        //add markers
        for(marker in markerOptions) {
            it.addMarker(marker)
        }


        val callback = GoogleMap.SnapshotReadyCallback(){
            saveSnapshot(it)
        }
        it.snapshot(callback)
    }
}

But before the onMapReady can even be called, the map itself needs to initiated.

var mMap: GoogleMap? = null

How do I create a map in memory only with no visual?

Thanks ^.^

Questioner
Micah Montoya
Viewed
57
Micah Montoya 2020-01-31 01:03

Looks like this is a limitation of Google Maps. Reading the GoogleMaps class documentation, it couldn't be done like you can with MapKit in iOS.