3

Hi I'm creating the marker like

Marker thisUserMarker = map.addMarker(new MarkerOptions()
           .position(new LatLng(CURRENT_LAT, CURRENT_LNG))
           .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marker_current_location)));

after this i want to make the marker as unclickable, according to the CURRENT_LAT and CURRENT_LNG. Is it possible to do that

Bahu
  • 1,516
  • 2
  • 28
  • 49

3 Answers3

4

I used this workaround, return true when you click on a marker

getMap().setOnMarkerClickListener(new OnMarkerClickListener() {

    public boolean onMarkerClick(Marker marker) {
        return true;
    }
});

Other posibility could be implement implements OnMarkerClickListener and in your onMarkerClick() compare it with the marker that you don't want to be clickable and do nothing.

@Override
public boolean onMarkerClick(final Marker marker) {

    if (marker.equals(myMarker)) 
    {
        //Do nothing
    }
}

You can also check this question : google-maps-api-v2-how-to-make-markers-clickable

Community
  • 1
  • 1
Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148
1

set Clickable like this.

     MarkerOptions marker=new MarkerOptions().position(resto).title(getAddress(28.6200, 77.2100));
    marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
    map.addMarker(marker);

   map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            if(marker.getTitle().equals(getAddress(28.6200, 77.2100))){
                Log.e("Delhi","Delhi");
                Log.e("Destance",""+distance(resto.latitude,resto.longitude,Delhi1.latitude,Delhi1.longitude,"M"));

            }else if(marker.getTitle().equals("Marker in Delhi1")){
                Log.e("Delhi1","Delhi1");

            }
                return false;

        }
    });

GetAddress metgod()

   public String getAddress(double lat, double lng) {
    Geocoder geocoder = new Geocoder(MapsActivity.this, Locale.getDefault());
    String Address=" ";
    Log.e("ADDRESS","ADDRESS");
    try {
        List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
        Address obj = addresses.get(0);
        String add = obj.getAddressLine(0);
        Address= obj.getAddressLine(0);

        add = add + "\n" + obj.getCountryName();
        add = add + "\n" + obj.getCountryCode();
        add = add + "\n" + obj.getAdminArea();
        add = add + "\n" + obj.getPostalCode();
        add = add + "\n" + obj.getSubAdminArea();
        add = add + "\n" + obj.getLocality();
        add = add + "\n" + obj.getSubThoroughfare();

        Log.e("IGA", "Address" + add);


    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }
    return Address;
}
Abhinav singh
  • 1,448
  • 1
  • 14
  • 31
  • For getAddress i'm getting "The method getAddress(double, double) is undefined for the type new GoogleMap.OnMarkerClickListener(){}" – Bahu Dec 28 '15 at 12:02
0

Maybe you can override the ClickListener. Im not sure if the lat and lng values are saved in the Marker arg0 event.

mMap.setOnMarkerClickListener(new OnMarkerClickListener()
                {
                    @Override
                    public boolean onMarkerClick(Marker arg0) {
                        return true;
                    }
                });  

Hope it helps.

miron123
  • 81
  • 1
  • 9