// Since we are consuming the event this is necessary to // manage closing opened markers before opening new ones Marker lastOpened = null; mMap.setOnMarkerClickListener(new OnMarkerClickListener() { public boolean onMarkerClick(Marker marker) { // Check if there is an open info window if (lastOpened != null) { // Close the info window lastOpened.hideInfoWindow(); // Is the marker the same marker that was already open if (lastOpened.equals(marker)) { // Nullify the lastOpened object lastOpened = null; // Return so that the info window isn't opened again return true; } } // Open the info window for the marker marker.showInfoWindow(); // Re-assign the last opened such that we can close it later lastOpened = marker; // Event was handled by our code do not launch default behaviour. return true; } });
// Since we are consuming the event this is necessary to // manage closing openned markers before openning new ones Marker lastOpenned = null; mMap.setOnMarkerClickListener(new OnMarkerClickListener() { public boolean onMarkerClick(Marker marker) { // Check if there is an open info window if (lastOpenned != null) { // Close the info window lastOpenned.hideInfoWindow(); // Is the marker the same marker that was already open if (lastOpenned.equals(marker)) { // Nullify the lastOpenned object lastOpenned = null; // Return so that the info window isn't openned again return true; } } // Open the info window for the marker marker.showInfoWindow(); // Re-assign the last openned such that we can close it later lastOpenned = marker; // Event was handled by our code do not launch default behaviour. return true; } });
Map<Integer, Marker> mMarkers = new HashMap<>(); public void createMarker(LatLng latLong, float thisNewColor){ MarkerOptions options = new MarkerOptions().position(latLong).draggable(false).icon(BitmapDescriptorFactory.defaultMarker(thisNewColor)); if(mMap != null) { if (mMarkers.contains(thisNewColor)){ Marker old = mMarkers.get(thisNewColor); old.remove(); } Marker marker = mMap.addMarker(options); marker.showInfoWindow(); mMarkers.put(thisNewColor, marker); CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLong, 17); mMap.animateCamera(cameraUpdate); mMap.setMyLocationEnabled(true); } }
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { Marker currentShown; public boolean onMarkerClick(Marker marker) { if (marker.equals(currentShown)) { marker.hideInfoWindow(); currentShown = null; } else { marker.showInfoWindow(); currentShown = marker; } return true; } });
Marker currentMarker; private void displaymap(String lat, String lon, String title) { if (currentMarker != null) { currentMarker.remove(); } MarkerOptions marker = new MarkerOptions().position(new LatLng(Double. parseDouble(lat),Double.parseDouble(lon))).title(title); marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_schoolbus)); currentMarker = map.addMarker(marker); currentMarker.showInfoWindow(); currentMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_schoolbus)); map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Double.parseDouble(lat),Double.parseDouble(lon)), 15)); }
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { Marker mLastMarker; @Override public boolean onMarkerClick(Marker marker) { if (marker.equals(mLastMarker)) { // Same marker clicked twice - hide InfoWindow mLastMarker = null; marker.hideInfoWindow(); } else { mLastMarker = marker; marker.showInfoWindow(); } return true; } });
Marker lastOpened = null; public OnMarkerClickListener getMarkerClickListener() { return new OnMarkerClickListener() { public boolean onMarkerClick(Marker marker) { if (lastOpened != null) { lastOpened.hideInfoWindow(); if (lastOpened.equals(marker)) { lastOpened = null; return true; } } marker.showInfoWindow(); lastOpened = marker; return true; } }; }
@Override public boolean onMarkerClick(final Marker marker) { LatLng p = marker.getPosition(); marker.remove(); final Marker m = mMap.addMarker(new MarkerOptions().position(p).title("new")); handler.post(new Runnable() { @Override public void run() { m.showInfoWindow(); } }); return true; }