Reputation: 179
I've written my custom location listener which checks the user's location in every 10 minutes and updates a marker on the map which denotes the user's location. The problem is that the marker is clickable i.e. it shows a button to get directions to the marker. I want to disable that, how can I do that?
Here's the function which creates/updates the marker
public void updateUserMarker() {
Double temp_latitude = ((MainActivity)mContext).mLatitude;
Double temp_longitude = ((MainActivity)mContext).mLongitude;
if(mMap!=null) {
if (user_marker == null) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(temp_latitude, temp_longitude));
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_marker_icon));
user_marker = mMap.addMarker(markerOptions);
} else {
user_marker.setPosition(new LatLng(temp_latitude, temp_longitude));
}
}
}
Upvotes: 1
Views: 4772
Reputation: 299
Try this code.
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
return true;
}
});
Returning true will also prevent info window from being opened.
For using this with a ClusterManager
:
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
if (marker == user_marker) {
return true;
}
return clusterManager.onMarkerClick(marker);
}
});
Upvotes: 2