Android onMarkerClick does not call after InfoWindow hides in GoogleMap Google Maps Android API v2

I am integrating the Google Maps API Android v2 into my application and weird marker behavior in GoogleMap. OnMarkerClickListener # onMarkerClick (marker marker) is not called after hiding InfoWindow. It doesnโ€™t depend on how I show InfoWindow (neither marker.showInfoWindow () nor

@Override public boolean onMarkerClick(final Marker marker) { ..... return true;} 

does not work. After I changed the position of the camera by touching or zooming, it works once. I saw the same behavior in GoogleMapDemo.

Here is my code

  private GoogleMap mMap; @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.map_address_activity); setUpMapIfNeeded(); // from oficial sample mMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(LatLng point) { mMap.clear(); mMap.addMarker(new MarkerOptions().position(point).title("Marker")); final CameraPosition cameraPosition = new CameraPosition.Builder().target(point).zoom(mMap.getCameraPosition().zoom).build(); mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); }); mMap.setOnMarkerClickListener(new OnMarkerClickListener() { @Override public boolean onMarkerClick(final Marker marker) { Log.e("TESTING", "on Marker click: " + marker.getTitle()); if (!marker.isInfoWindowShown()) marker.showInfoWindow(); else marker.hideInfoWindow(); return true; } }); } 

Can you help me handle click events on the marker after hiding InfoWindow?

+4
source share
1 answer

This is what was supposed to happen! onMarkerClick will be called only when you click on the marker, but not when hiding information.

If you want to listen to the InfoWindows hide event, you must implement your own logic either in the onMarkerClick method, where you hide the InfoWindow, or in an override of the MapClick method (since information can be hidden when clicking on any card). In the latter case, you should keep the link on the last marker with the activated information window and check the status of the window to implement the logic.

+2
source

All Articles