经过一些工作后,我的路线应用程序运行良好。
我唯一想添加的是双击放大功能,但我不知道如何添加。
你能给我一个提示吗?
我也一直在寻找答案/示例,但找不到有效的代码。
最后,这是对我有用的代码:
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>
不要忘记在这里替换android:apiKey
与你的价值apiKey
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)