Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapView onCLick Event Listener

So I've been trying to detect click events to a MapView in order to start a method with the click.

Trying any variation of standard onClickListener or onTouch were no good.

I do not want to add an overlay of to "catch" clicks on a certain part of the map. I want the map to continue to be responsive to drag,zooms, etc.

Any help would be appreciated.

like image 704
Givi Avatar asked Feb 11 '14 11:02

Givi


3 Answers

So, apparently the solution is quite simple. I guess it was added in one of the last support libs. GoogleMap now supports onMapClick.

mMapView.getMap().setOnMapClickListener(new OnMapClickListener()
                {
                    @Override
                    public void onMapClick(LatLng arg0)
                    {
                        android.util.Log.i("onMapClick", "Horray!");
                    }
                });
like image 101
Givi Avatar answered Sep 19 '22 15:09

Givi


In the new version of Google Play services, you should call the method after the map is ready, at the onMapReady(GoogleMap map); callback.

 @Override
public void onMapReady(GoogleMap googleMap) {
    googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener()
    {
        @Override
        public void onMapClick(LatLng arg0)
        {
            android.util.Log.i("onMapClick", "Horray!");
        }
    });
}
like image 45
nmvictor Avatar answered Sep 20 '22 15:09

nmvictor


public class MapView  implements OnMapReadyCallback, GoogleMap.OnMarkerClickListener {

   @Override
   public boolean onMarkerClick(Marker marker) {
       println("click marker");
   }
}
like image 37
Umesh Maharjan Avatar answered Sep 20 '22 15:09

Umesh Maharjan