android-maps-compose
android-maps-compose copied to clipboard
Map Snapshots
Please add support for taking map snapshots: GoogleMap::snapshot(@NonNull GoogleMap.SnapshotReadyCallback callback)
@MobileAppsGO Thank you for opening this issue. 🙏 Please check out these other resources that might be applicable:
- Support Console - If you have a support contract.
- Discord - chat with other developers
-
StackOverflow - use the
google-maps
tag - Google Maps Platform issue trackers
This is an automated message, feel free to ignore.
I would also want this feature. Thanks!
Quickest is to expose a function in CameraPositionState
although that won't to be the right place to do so. A state holder object like GoogleMapState
that contains CameraPositionState
etc. would be a better approach. Would be worth addressing that for the next major version change.
any updates on this?
@recoverrelax you can use MapEffect
to get the snapshot.
Something like:
GoogleMap {
MapEffect { map ->
map.snapshot { snapshot ->
// Got snapshot here
}
}
}
Is this going to be an official feature? It would be very nice to have a map span to base snapshot on, cause CameraPosition is very limited to handle multiple markers with a good framing displaying all markers.
Is this going to be an official feature? It would be very nice to have a map span to base snapshot on, cause CameraPosition is very limited to handle multiple markers with a good framing displaying all markers.
Can you clarify what you mean by 'It would be very nice to have a map span to base snapshot on'?
Yes.. I think we should have other options of zoom, since in my case I need to frame multiple markers, and set the snapshot with a zoom that will show every marker wihtout being too far.
Any update on this? Is snapshot functionality is available ?
I have been using in production the recommend by @arriolac code snippet:
GoogleMap {
MapEffect { map ->
map.snapshot { snapshot ->
// Got snapshot here
}
}
}
and is working. The downside is that in very rare cases and completely randomly it throws:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isMutable()' on a null object reference
at android.graphics.Canvas.<init>(Canvas.java:113)
at com.google.maps.api.android.lib6.impl.a.a(:com.google.android.gms.policy_maps_core_dynamite@[email protected]:3)
at com.google.maps.api.android.lib6.phoenix.cb.run(:com.google.android.gms.policy_maps_core_dynamite@[email protected]:9)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8194)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
maybe because MapEffect
is still experimental
? Will it be any update any time soon?
We are still waiting for the stable official implementation, correct?
@petros-chariskos i twas able to fix that NPE by putting that MapEffect behind a callback of "onMapLoaded". It's a parameter for GoogleMap. Try it, I hope it helps. I never seen the NPE ever since.
thank you @alexandrupele, I am already doing that and still getting the NPE. I can give the code snippet in case there is something wrong with my implementation but I think it's pretty straight forward.
var isMapLoaded by remember { mutableStateOf(false) }
val mapBitmap: MutableState<Bitmap?> = remember { mutableStateOf(null) }
GoogleMap(
modifier = Modifier,
cameraPositionState = cameraPositionState,
properties = mapProperties,
uiSettings = uiSettings,
onMapLoaded = {
isMapLoaded = true
}
) {
MapMarker(
context = LocalContext.current,
state = rememberMarkerState(position = LatLng(latLng.latitude, latLng.longitude)),
iconResourceId = iconResourceId
)
if (isMapLoaded) {
MapEffect { map ->
map.snapshot { snapshot ->
mapBitmap.value = snapshot
}
}
}
}
Hi! Is this feature still being working on? Or any other way to access the googleMap instance without the use of MapEffect?Thanks!
Would be awesome to have this feature +1
@petros-chariskos try updating to compose maps 4.3.3. I see they've fixed a few things about the phase of the composition at which point the map is rendered. Let me know if it fixes it for you. I've also seen this crash again, now I'm hoping it goes away with the new version. I had 4.3.0 before.
Thanks @alexandrupele, I have updated the compose maps to 4.3.3 and this release is already in production since a couple of days ago. I hope this solves it, otherwise I will update the thread.
[Thread update] With com.google.maps.android:maps-compose
in 4.3.3 the NPE: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isMutable()' on a null object reference
still appears in the logs in production.
I still get this crash. Anyone found a solution for it?
@petros-chariskos check this thread until the end, i think the answer is there: https://issuetracker.google.com/issues/290806747