Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleMaps V2 android get marker icon

I'm currently implementing GoogleMapsV2 and try to port the old functionality I had in MapsV1. in V1, I was able to subclass an OverlayItem and save the icon i put inside. Now I have to create a MarkerOption based on a model object, add it to the GoogleMap to get a Marker back.

Because the Marker class is final, and GoogleMaps isn't providing a Method to get a handle on it (like a SQLiteCursorFactory), I feel unable to get the icon back I put inside.

If i keep the MarkerOptions object, I could get back a BitmapDescriptor which has only one (obfuscated) method aW() which is returning a b object.

I'm quite shure that the Bitmap must be somewhere inside this object because its drawn on the GoogleMap. What is the best way to get it back from the marker.

I'm currently mapping the Marker to my model upon creation inside a HashMap<Marker, ModelObj> but from there I have to re-create the icon everytime I want to access it. This feels simply wrong, and I'm wondering if there is a better method of accessing it.

like image 831
Rafael T Avatar asked Jul 13 '26 23:07

Rafael T


1 Answers

I'm quite shure that the Bitmap must be somewhere inside this object because its drawn on the GoogleMap.

That's far from certain. The map is rendered by another process. So, while the Bitmap is in that process, it may not be in yours.

What is the best way to get it back from the marker.

You don't. That's a write-only API.

I'm currently mapping the Marker to my model upon creation inside a HashMap but from there I have to re-create the icon everytime I want to access it.

Then cache it yourself. Nowadays, Marker has getId(), which is probably better than using Marker itself as the key. But then either tuck your icon into ModelObj or have a separate bitmap cache. You will have to determine for yourself if the CPU vs. RAM trade-off warrants caching or regenerating the icon.

like image 161
CommonsWare Avatar answered Jul 15 '26 11:07

CommonsWare