Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 775
SachinS Avatar asked Dec 15 '15 04:12

SachinS


People also ask

How do you handle touch events in a fragment?

OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if(event. getAction() == MotionEvent. ACTION_MOVE){ //do something } return true; } }); //here the rest of your code return view; MotionEvent.

What is MapFragment?

public class MapFragment extends Fragment. A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs.


1 Answers

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
            }
        });
like image 84
Arth Tilva Avatar answered Oct 01 '22 15:10

Arth Tilva