我无法找到如何拦截新的地图API V2地图上触摸的例子。
I can't find an example on how to intercept the map touch on new maps api v2.
我要当用户触摸地图,以阻止一个线程(在我的当前位置在地图的定心)就知道了。 请给我一个起点。 谢谢你。
I need to know when user touches the map in order to stop a thread (the centering of the map around my current location). Please, give me a starting point. Thank you.
@ape这里写一篇关于如何拦截地图上点击一个答案,但我需要截取的接触,那么他建议在评论下面的链接它回答How要在地图在谷歌地图API V2处理onTouch事件?
@ape wrote here an answer on how to intercept the map clicks, but i need to intercept the touches, then he suggested the following link in a comment of its answer How to handle onTouch event for map in Google Map API v2?
该解决方案似乎是一个可能的解决方法,但建议code是不完整的。 出于这个原因,我重写,并对其进行了测试。 现在,它的工作原理。 这是工作code:
That solution seems to be a possible workaround but the suggested code was incomplete. For this reason I rewrote and tested it. Now it works. Here it is the working code:
我创建的类MySupportMapFragment.java
I created the class MySupportMapFragment.java
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MySupportMapFragment extends SupportMapFragment {
public View mOriginalContentView;
public TouchableWrapper mTouchView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
mOriginalContentView = super.onCreateView(inflater, parent, savedInstanceState);
mTouchView = new TouchableWrapper(getActivity());
mTouchView.addView(mOriginalContentView);
return mTouchView;
}
@Override
public View getView() {
return mOriginalContentView;
}
}
我甚至创建的类TouchableWrapper.java:
I even created the class TouchableWrapper.java:
import android.content.Context;
import android.view.MotionEvent;
import android.widget.FrameLayout;
public class TouchableWrapper extends FrameLayout {
public TouchableWrapper(Context context) {
super(context);
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
MainActivity.mMapIsTouched = true;
break;
case MotionEvent.ACTION_UP:
MainActivity.mMapIsTouched = false;
break;
}
return super.dispatchTouchEvent(event);
}
}
在布局中我宣布它是这样的:
in the layout i declare it this way:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/buttonBar"
class="com.myFactory.myApp.MySupportMapFragment"
/>
只是为了测试主要活动我只写了以下内容:
Just for test in main Activity i wrote only the following:
public class MainActivity extends FragmentActivity {
public static boolean mMapIsTouched = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}