1

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));
            }
        }

    }

enter image description here

iamlegend
  • 159
  • 3
  • 14

1 Answers1

1

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);
        }
    });
Oguz Babaoglu
  • 279
  • 2
  • 7
  • 1
    This won't work for me. I'm already using android's ClusterManager as my click listener. – iamlegend Apr 18 '15 at 22:10
  • You can intercept the click and check if it is your location marker that is clicked. So inside your click listener you'll do this: `if (marker == user_marker) return true` `else return clusterManager.onMarkerClick(marker)` – Oguz Babaoglu Apr 19 '15 at 16:00