我有以下代码可以在 Google 地图上显示我的实际位置:
public class LocationProjectActivity extends MapActivity implements OnTouchListener {
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
private MyOverlays itemizedoverlay;
private MyLocationOverlay myLocationOverlay;
private GeoPoint MyPoint;
public static int longitude;
public static int latitude;
private GeoPoint destinationPoint;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
mapView.computeScroll();
mapController = mapView.getController();
mapController.setZoom(13);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new GeoUpdateHandler());
myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.runOnFirstFix(new Runnable() {
public void run() {
mapView.getController().animateTo(myLocationOverlay.getMyLocation());
}
});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
System.out.println("SCREEN WAS CLICKED");
return true;
}
我想要做的是在我触摸屏幕时捕捉,但该方法从未被调用。我已经搜索并找到了这个: 地图中的 OnTouch
我尝试了一切,唯一有效的代码是:
mapView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// Your code and remember to return true!
return (true);
}
});
问题是,如果我使用这段代码,我的 MapView 会失去它已经拥有的自然翻转和缩放,那么我怎样才能在我的 MapView 中拥有一切?
谢谢你。