How to simulate Google maps Marker inheritance on Android - android

I would like to simulate an inheritance of Marker from Google Maps API V2. I know it's impossible to inherit from Marker because Marker is a final class and that's my problem.
My final goal: create a Marker (let's call this one MainPoint) which deploys 5 others Marker (let's call them Petal) when I click on it and hides them when I click again.
When Petals are deployed around MainPoint, thanks to onMarkerClickListener I can catch the marker but I can't identify if this marker is a MainPoint or a Petal.
If I could make Petal and MainPoint inherit from Marker or even put a tag on it, I would just have to check if this is a Petal or a MainPoint to know which method I have to call but with only the instance of a Marker, the only way I found is to check every instance of every MainPoint and its Petals if it's equal to the marker clicked.
I hope you can help me to find a way to design this situation.

I can't identify if this marker is a MainPoint or a Petal
Maintain a HashMap mapping petal Marker IDs to main point Marker IDs. Look up your Marker in the HashMap to find its associated main point, and if you get back null, you know that it is a main point.

Related

How do I add markers to a Mapbox map outside of a Mapbox event?

All the examples I've seen for adding a marker to the map show the marker being added in the "onMapReady" callback or the "onMapClick" callback. I have an app that periodically finds the user's latitude and longitude and I want to add a marker to the map when the lat and lng updates. This happens outside of the previously mentioned callbacks. How would I do that? I need access to the Style object of the map but it's only accesible inside the callbacks.
The reason these callbacks (in particular onMapReady) are used in all the examples is to ensure that the mapboxMap objects's style has been loaded by the time you attempt to modify it - if it isn't there is the potential for some asynchronous weirdness as the map renders.
I would recommend you still include the logic for adding the periodic lat/lon coordinates as markers within the onMapReady callback.
⚠️ Disclaimer: I currently work for Mapbox ⚠️

Google Maps How do I get the current CameraLocation object?

When I close my map or switch a different activity, the map calls the onSaveInstanseState(). I want to get the current camera position and LatLng so that when the user switches back to the map, they will be in the same location.
Thank you.
Google Maps have a getCameraPosition() method.
To get the latLang, you simple have to get the camera position then get the target. Such as:
LatLang latlang = googleMaps.getCameraPosition().target

Is there a way to determine a user's current map view area?

Is there a way to determine a user's current map view area, whether in Google or Apple Map?
I'm in the process of designing a geolocation app, and want to show the names of locations near the user. I could use distance from user as the parameter, but want to see if there's a way to only show the names in the current map area that's being viewed instead. I've done a decent search but haven't found any method.
Thanks!
There's an object called VisibleRegion in the GoogleMap that gives you this information (Google Maps V2 for Android). You get this from the GoogleMap object with the following code
VisibleRegion region = getMap().getProjection().getVisibleRegion();
I called getMap() to get the GoogleMap object because I was in the context of a MapFragment...not sure what your implementation is.
http://developer.android.com/reference/com/google/android/gms/maps/model/VisibleRegion.html

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.
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.

Add 1000's Markers to android Googlemap

I am developing a GoogleMap based android application.
I need to display 1000's of Markers on the map.
Currently I retrieve the Latitude and Longitude for each marker from an SQLite database loader and add the markers in the public void onLoadFinished(final Loader loader, final Cursor cursor) method.
this approach gives a very bad user experience though, as the application does not respond while i add the Markers.
how can i add 1000's of markers to a googlemap and keep my application responsive?
as i have to add the markers to the map on the main UI thread.
One possible way is to only add Markers when they fall into visible region of the map.
You would actually have to move your calls to addMarker from onLoadFinished to onCameraChange and in onLoadFinished only create a list of data needed to create these Markers. In the simplest form this might be List<MarkerOptions>.
Android Maps Extensions mentioned by Lalit Poptani in the comments above can handle that for you even if you don't want to use clustering. You simply leave your code like it is and only make a call like
googleMap.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true));
after replacing Google Maps Android API v2 with this extensions lib.
You can use Spatial Lite provider with geoserver to provide WMS maps.
In android you can set a tile provider to consuming such tile maps.

Categories

Resources