如何在android中处理谷歌地图的触摸事件(在片段内)

时间:2017-01-14 20:07:45

标签: android google-maps android-fragments

我是Android的新手,我想像这篇文章一样处理mapView上的触摸 Google Maps Android API v2 - detect touch on map

但它完全不同,在我的情况下,我使用片段类来处理我的所有地图业务。

我的布局:

$ g++ *.cpp -o bfd
bfd.cpp: In member function ‘int BfdEndpoint::Start()’:
bfd.cpp:34:55: error: cannot convert ‘void* (BfdEndpoint::*)()’ to ‘void* (*)(void*)’ for argument ‘3’ to ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
  rv = pthread_create(RxTh,NULL,&BfdEndpoint::RxSM,NULL);

我已经尝试使用setOnTouchListener但它不起作用

<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>

我错过了什么吗?请帮忙!感谢

1 个答案:

答案 0 :(得分:0)

在GoogleMap对象上设置点击侦听器,而不是在MapView上设置

GoogleMap map;

map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(final LatLng clickCoords) {
          //do your code here
        }
};
相关问题