我已经创建了一个map overlay类,并重写了如下所示的Ontouchevent方法:
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
//TO-DO here we will capture when the users
//has pointed a point to go..
if(event.getAction() != MotionEvent.ACTION_MOVE){
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6() / 1E6,
p.getLongitudeE6() / 1E6, 1);
String add = "";
if (addresses.size() > 0)
{
for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();
i++)
add += addresses.get(0).getAddressLine(i) + "\n";
}
Log.e("##################",
"screen touched: lat:"+(p.getLatitudeE6()/ 1E6)+"long:"+(p.getLongitudeE6()/ 1E6));
showMap((p.getLatitudeE6()/ 1E6),(p.getLongitudeE6()/ 1E6));
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}else
return false;
}
问题是每次我在地图上做手势时都会画地图,我只想在我点击地图上的一个点而不是拖动地图时才画,这种方法正确吗?如何实现这一点?