我的路线应用工作的一点点后工作正常:) 我只想补充一点的是在功能上双击缩放,但我不知道怎么...双击 - >放大Android MapView?
你可以给我一个提示?
不错的问候, poeschlorn
我的路线应用工作的一点点后工作正常:) 我只想补充一点的是在功能上双击缩放,但我不知道怎么...双击 - >放大Android MapView?
你可以给我一个提示?
不错的问候, poeschlorn
实施GestureListener接收doubleTap事件。
一个旧帖子,我知道,但是这个解决方案也有效:double click/tap map zoom (Android)
我觉得他固定他在他自己的帖子中的错误,所以只是使用问题的一部分,而不是答案(他们是可怕的:))
我也一直在寻找一个答案/例子,但没有找到工作代码。
最后,这里是一个的工作对我来说代码:
MyMapActivity.java
public class MyMapActivity extends MapActivity
implements OnGestureListener, OnDoubleTapListener {
private MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.mapView);
}
@Override
public boolean onDoubleTap(MotionEvent e) {
int x = (int)e.getX(), y = (int)e.getY();;
Projection p = mapView.getProjection();
mapView.getController().animateTo(p.fromPixels(x, y));
mapView.getController().zoomIn();
return true;
}
// Here will be some autogenerated methods too
OnDoubleTap.java
public class OnDoubleTap extends MapView {
private long lastTouchTime = -1;
public OnDoubleTap(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
long thisTime = System.currentTimeMillis();
if (thisTime - lastTouchTime < ViewConfiguration.getDoubleTapTimeout()) {
// Double tap
this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
lastTouchTime = -1;
} else {
// Too slow
lastTouchTime = thisTime;
}
}
return super.onInterceptTouchEvent(ev);
}
}
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<azizbekyan.andranik.map.OnDoubleTap
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="YOUR_API_KEY" />
</LinearLayout>
不要忘记用您的apiKey
替换这里的android:apiKey
值。
'onInterceptTouchEvent'处理程序的来源似乎是[此博客文章](http://nocivus.posterous.com/double-clicktap-detection-on-a)。我通过设置ViewConfiguration.getDoubleTapTimeout()来改进Andrianik的代码。 – JJD 2012-10-17 22:35:04
当你要放大和缩小
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
long thisTime = System.currentTimeMillis();
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = (WindowManager) activity.getSystemService(activity.getApplicationContext().WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels;
if (thisTime - lastTouchTime < ViewConfiguration.getDoubleTapTimeout()) {
// Double tap
if((height/2)>ev.getY()){
// Zoom IN
this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
}else{
this.getController().zoomOutFixing((int) ev.getX(), (int) ev.getY());
//Zoom Out
}
lastTouchTime = -1;
} else {
// Too slow
lastTouchTime = thisTime;
}
}
return super.onInterceptTouchEvent(ev);
}
如果有人正在寻找答案的新的GoogleMap(自谷歌-PL ay-service:9+)
case MotionEvent.ACTION_DOWN:
x1 = m.getX();
if ((System.currentTimeMillis() - systemTime) < 200) {
mGoogleMap.animateCamera(CameraUpdateFactory.zoomIn());
}
systemTime = System.currentTimeMillis();
break;
case MotionEvent.ACTION_UP:
systemTime = System.currentTimeMillis();
...
break;
在那篇文章中没有双击它为什么每个人都重定向到特定的线程: – Necronet 2011-08-24 20:24:01