我的路線應用工作的一點點後工作正常:) 我只想補充一點的是在功能上雙擊縮放,但我不知道怎麼...雙擊 - >放大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