Reputation: 1428
I'm new to Android and I want to handle touches on mapView like this post Google Maps Android API v2 - detect touch on map
But it quite difference, in my cases, I use fragment class to handle all my map business.
My layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="@+id/buttonTracking"
... />
</LinearLayout>
I have already try to use setOnTouchListener but it not work
public class MapsFragment extends Fragment implements PermissionsFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ll = (LinearLayout) inflater.inflate(R.layout.fragment_maps, container, false);
mMapView = (MapView) ll.findViewById(R.id.map);
ll.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event){
Log.e("INFO", "Touched");
return true;
}
});
}
}
Did I miss anythings? Please help! Thanks
Upvotes: 2
Views: 2613
Reputation: 463
Set click listener on GoogleMap object not on MapView
GoogleMap map;
map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(final LatLng clickCoords) {
//do your code here
}
};
Upvotes: 2