After a while of googling I cannot find what I need, I see some libraries which look to do it but I have already implemented the system using androids default methods.
I set the markers like so:
theMap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lon))
.title(title)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_map32))
.snippet(strap));
However I need a 'detail disclosure button' like on iOS (transitioning app from iOS to Android) and I can't seem to add a button to the marker - is it possible using androids system?
This cannot be done.
from the docs
Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.
in other words you cannot put a button in the infowindow and be able to use it. You will need to use a dialog of sorts if you want to do something like that
There is always some way.
A nice hack can be found here: https://stackoverflow.com/a/15040761/2183804
I haven't tested it myself, but from the comments there (and the amount of upvotes) we can deduce it works well.
You can track clicks only on Marker. If you want a button on marker - click on marker & show a dialog with buttons.
Related
I'm using MapActivity and I would like to put a progress bar in the marker popup that appears by clicking on it. I would like to put it under the marker title, in the area where the snippet would have been.
the marker I use is declared as it follows
new MarkerOptions().position(infoLocal.getUserLocation()).title("Your Location").snippet("This is you!").icon(BitmapDescriptorFactory.fromResource(R.drawable.player3)).anchor(0.5f, 0.5f)
As per the Android docs:
'An info window is not a live View. Instead, the view is rendered as an image on the map. As a result, any listeners you set on the view are disregarded and you cannot distinguish between click events on various parts of the view. You are advised not to place interactive components — such as buttons, checkboxes, or text inputs — within your custom info window.'
Hence you can not put live components (like progress bar) in a info window, As it converts the whole view to an image.
If you still want to achieve this, this library may help:
https://github.com/Appolica/InteractiveInfoWindowAndroid
For my Android App I'm using MapBox. Tapping a marker shows a calloutview in the shape of a balloon like expected. Google maps uses a different type of callout view. A view appears on the bottom and when tapped, the view scrolls over the map showing more information about the marker. Is there a specific name for this view? Or maybe a library which does the same thing? Or is it completely custom?
If so is this accomplished by adding a new fragment on top of the MapView? Any help would be much appreciated.
Added some screenshots to clarify what I mean.
Please don't mind the volume bar as it's ridiculously hard to take a screenshots without my device registering a single volume down push -_-
This is not really a view affiliated with the map, so it wouldn't be similar to a Tooltip or callout - you would listen for a touch event on a marker, and then rearrange the view surrounding the MapView, transitioning a separate detail view up and transitioning the map to a different centerpoint.
i would like to ask a question with regards to AlertDialogs which i would like to use in GoogleMaps V2. I read about the custom InfoWindow documentation from the android developers and noticed that they advised not to put any interaction widgets (Buttons, Textbox etc etc) onto an OnClick function. Now, i would like to know if i could use a default alert dialog and put it into an OnClick function for the custom InfoWindow. Is it possible?
Yes that should work fine. The reason why you should not (and cannot, really) put interactive elements in an InfoWindow is because the InfoWinow is statically rendered when shown, making any interactive elements you place in it effectively useless.
Currently i can open only 1 infowindow on the clicked marker, but I would like to have infowindows on all markers and not closing them on click.
How can I have InfoWindows on all markers and prevent from automatic closing them on click ?
You cannot have all info windows shown at the same time.
You can however make a custom marker icon, which will include some text. This icon might look like a marker with info window above. That's up to you.
You need to create a new InfoWindow for each marker. The reason one closes as another opens is because they are both using the same object (InfoWindow).
Or at least without any code that's my guess.
I was viewing a different question Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps) and as you can see he's using the requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); to make the map v2 use the full screen. I tried this but the my location button is partially covered by the action bar on mine unlike his. Does anyone know how to move it down slightly?
Thanks!
Unfortunately you don't have any control over this button. Obviously, you can search for this button id in android sources and change layout params manually from the code, but I definitely wouldn't do that.
This button is super easy to implement yourself. So I recommend to disable built-in "locate me" button and implement your own which will be positioned right below the action bar.
To disable it use:
googleMap.setMyLocationEnabled(false);
New button onClick method content:
googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(googleMap.getMyLocation().getLatitude(),
googleMap.getMyLocation().getLongitude())));
You can just get the view by its id and re-set the top margin Apparently the id is always 2, but this isn't documented and your app will break when/if the id ever changes. Like Pavel said, it's safer to make your own location button and wire it up.
Unfortunately, calling ActionBar.getHeight() in your onCreate will always return 0 since layout hasn't finished. The way to get the real heigh is by using a listener on the ViewTreeObserver:
mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
int actionBarHeight = getActionBar().getHeight();
// TODO: set margin of views dependent on actionbar height
// remove the listener
mainLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
}