Disable infowindow when click cluster in mapV2 - android

I have referred this https://developers.google.com/maps/documentation/android/utility/marker-clustering link to implement simple cluster in my application
Now I want to disable the cluster onclick
In my screen when I click 3 my info window is showing but I don't want to show infowindow; instead of that, I need to zoom the map.
I have tried
mClusterManager.onInfoWindowClick(null);
mClusterManager.setOnClusterClickListener(null);
mClusterManager.setOnClusterInfoWindowClickListener(null);
mClusterManager.setOnClusterItemClickListener(null);
mClusterManager.setOnClusterItemInfoWindowClickListener(null);
// render.setMarkersToCluster(false);
render.setOnClusterClickListener(null);
render.setOnClusterInfoWindowClickListener(null);
render.setOnClusterItemClickListener(null);
render.setOnClusterItemInfoWindowClickListener(null);
These tries are not at all working; please give me some idea of what to do.

So as we discuss above:
You can use hideInfoWindow() method
Set Renderer from cluster manager as following:
mClusterManager.setRenderer(myClusterRenderer);
Get the marker and hide it as following:
#Override
public void onClusterItemInfoWindowClick(final myPOI item) {
myClusterRenderer.getMarker(item).hideInfoWindow();
}

Related

GoogleMaps marker OnClick - Xamarin

Hi everyone I am using the GoogleMaps Gms.Maps class to show a map on my app (Xamarin.Android).
I am trying to make it so when you click on a marker it will take you to a specific page on my mobile app. however it seems the markers already have on click functions that centre it and display the title. I haven't created this and also can't find it (see below)
any idea how I would edit this function or create a new one?
thanks,
Implement Android.Gms.Maps.GoogleMap.IOnMarkerClickListener on your Activity, Fragment or in a separate class and assign that to the GoogleMap instance via the SetOnMarkerClickListener method.
Example:
public class MyMarkerClickListener : Java.Lang.Object, IOnMarkerClickListener
{
Context context;
public MyMarkerClickListener(Context context)
{
this.context = context;
}
public bool OnMarkerClick(Marker marker)
{
Toast.MakeText(context, $"{marker.Title} was tapped", ToastLength.Long).Show();
return true;
}
}
Usage:
googleMap.SetOnMarkerClickListener(new MyMarkerClickListener(this));
Note: Normally the listener would be assigned in the OnMapReady callback
Google Docs: GoogleMap.OnMarkerClickListener
Returns:
true if the listener has consumed the event (i.e., the default behavior should not occur); false otherwise (i.e., the default behavior should occur). The default behavior is for the camera to move to the marker and an info window to appear.
Well what #SushiHangover has answered is right but the easier way of doing it would be adding a marker click event:
Googlemapsobj.MarkerClick+= (s,e)=>
{//yourcodeforNextPage };
Here you wont have to worry about the default behaviour as it will leave the page as soon as it is clicked.

Listener to map touch outside of the markers

I am using the google map api with some markers. I also overrode the infoWindow as below to show custom text.
public void setUpMap() {
final GoogleMap map = mMapView.getMap();
map.clear();
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
private View mHolder;
#Override
public View getInfoWindow(final Marker marker) {
Log.d("MAP", "Map clicked on marker = " + maker);
etc....
this works fine and I change the icon of each marker when clicked making them visually selected. However, I want to "unselect" all markers. The problem is that I don't know how to add a listener that gets triggered from outside of the markers.
In other words, my listener "getInfoWindow" gets trigger only when a marker is touched. I want the opposite. Some sort of listener that tells me that the user touched the map but not the markers.
Can this be done easily? Any pointers are greatly appreciated.
thx!
Ok, I suppose that's really easy.
You have OnMarkerClickListener and OnMapClickListener.
So, in your case just register OnMapClickListener and in onMapClick() you can do what you need.
One more thing - when you add markers, store them in Arraylist - then at any time you can do whatever is needed - even remove all markers from the map.
This is useful only when working with the Info Window.
In my case, when the user clicks the marker, the corresponding Info window appears. So when the user clicks in the map outside the marker, the Info Window closes and that event is detected by the map.
// Detect when Marker's Info Window is closed
googleMap.setOnInfoWindowCloseListener(new GoogleMap.OnInfoWindowCloseListener() {
#Override
public void onInfoWindowClose(Marker marker) {
// Do whatever you want to do here...
}
});

Android Google Maps V2 Cluster hide infoWindow

In Android project, I'm using Google Maps Android API Utility Librairy in order to use clustering solution.
On each single marker or clustering marker an InfoWindow is opening on a touch on the selected marker. Then on a touch on the infoWindow I use theses events :
...
mClusterManager.setOnClusterInfoWindowClickListener(this);
mClusterManager.setOnClusterItemInfoWindowClickListener(this);
...
and :
#Override
public void onClusterInfoWindowClick(Cluster<JobItem> cluster) {
// Here I go to a new fragment A, list of items.
}
#Override
public void onClusterItemInfoWindowClick(JobItem item) {
// Here I go to a new fragment B, item's details
}
When I come back to the map (popBackStack from fragment A or B) the infoWindow is always open. I would like to hide them programmatically when I go to fragment A or B.
I found it's possible to call methods hideInfoWindow() from markers object but in theses two events markers are not passing through parameters.
Any idea on how to hide the infoWindow ?
I found a solution that work for me, add this code on the onResume of your fragment, it will close all opened InfoWindow.
java.util.Collection<Marker> markerCollection = mClusterManager.getMarkerCollection().getMarkers();
for(Marker m : markerCollection){
if(m.isInfoWindowShown())
m.hideInfoWindow();
}

Adding a custom OnMarkerDragListener makes markers no longer draggable

I'm using Google Maps v2 in an Android application that I'm writing. After creating the map and adding all the markers to it, I make all the markers draggable by using marker.setDraggable(true); for each marker on the map.
If I run the code like this, the markers are indeed draggable. However, I'd like to change the icon or color of the marker while it's being dragged, so I set up an OnMarkerDragListener, like so:
map.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
#Override
public void onMarkerDragStart(Marker marker) {
marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
}
#Override
public void onMarkerDrag(Marker marker) {
}
#Override
public void onMarkerDragEnd(Marker marker) {
marker.setIcon(BitmapDescriptorFactory.defaultMarker());
}
});
After adding in that block of code, though, the markers are no longer draggable. The color successfully changes in both the onMarkerDragStart and onMarkerDragEnd methods, but that's it. Can anyone explain what I'm doing wrong here, and why the markers aren't getting dragged ?
i would say that the problem comes from changing the icon rather than from settings the listener.
Please note that Marker.setIcon is not a function that is available in all the versions of the GoogleMaps V2 API. This means that probably it is not available in the library you have, or in the version of the play services installed in the device in which you are trying your app, and that could be causing any kind of malfunction.
As you can read here that function was added in May 2013. Please try updating everything, the google-play-services_lib, and the play services installed in the device.
If this happen to fix it, then you can try to change the icon only depending on the version installed on the mobile.

Android Google Maps v2 permanent Marker InfoWindow

The default behavior for an InfoWindow is to hide if the map the marker is in, or the marker itself are tapped.
Is there any way to make the InfoWindow permanent so you can't hide it?
I have disabled all gestures in the map, but the InfoWindow still disappears when you tap.
visceralG's solution is what I would do in the first place, but there is also (untested) alternative:
keep a reference to marker showing info window (from getInfoContents)
in onMapClick call markerShowingInfoWindow.showInfoWindow() to force it back
if the above doesn't work, put markerShowingInfoWindow.showInfoWindow() inside Runnable.run() and post it with Handler or View
Not that I'm aware of. You're best bet is to create your own custom icon for the map marker that includes a drawn "infoWindow." It will then require some custom drawing on the infoWindow section of the icon bitmap to produce the same effect as a normal infoWindow, but it's not too terrible to pull off. Not quite as easy as the solution you were looking for, but it'll get you where you were wanting to go. Hope that helps!
Assuming that you already know how to setup info windows, these lines will make your infoWindow, for any one marker, permanent:
final Marker myMarker = mGoogleMap.addMarker(mDriverMarker);
myMarker.showInfoWindow();
mGoogleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
#Override
public void onMapClick(LatLng latLng) {
myMarker.showInfoWindow();
}
});
mGoogleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
myMarker.showInfoWindow();
return true;
}
});

Categories

Resources