How to handle touch event on google map (MapFragment)? [duplicate]
Asked Answered
B

2

9

I am looking for a proper touch event that will be triggered when user touches the map (Google Maps Android API). Does anyone have an idea as to how to do it ?

Baht answered 15/12, 2015 at 4:36 Comment(1)
#14013502Cordellcorder
I
11

You can directly add click listener and get position of touch on Map in form of Location.

 map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                
              //Do what you want on obtained latLng
            }
        });
Insurrectionary answered 15/12, 2015 at 4:56 Comment(1)
I tried it. It's working.Thanks for your support.Baht
L
2

You should use SetOnMapClickListener. Hope below demo code will help you to do so.

googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener()
{
    @Override
    public void onMapClick (LatLng latLng){

    latitude = latLng.latitude;
    longitude = latLng.longitude;

    myMarker = googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)));
}
});
Libelant answered 15/12, 2015 at 4:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.