我可以执行不需要长按的 onTap,但仍为其他事件启用长按吗?
目前我在谷歌地图上有一系列标记。我希望能够从长按地图上的任何位置获取纬度和经度,并且希望在快速单击标记时打开消息框对话框。我的问题是,通过设置长按来工作,它使得我的 onTap 函数只有在我长按时才会被调用。只有当我不点击标记时,longlick 才可能工作吗?
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
return gestureScanner.onTouchEvent(event);
//return false;
}
////////////////////////////////////
// Handle the clicking of a marker
//
////////////////////////////////////
@Override
protected boolean onTap(int index)
{
System.out.println("OnTap");
OverlayItem item = mOverlays.get(index);
int localLat = item.getPoint().getLatitudeE6();
int localLong = item.getPoint().getLongitudeE6();
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
// Get the titles
dialog.setTitle(item.getTitle());
// Get the text for the message
//dialog.setMessage(item.getSnippet());
dialog.setMessage("Latitude: " + localLat + "\nLongitude: " + localLong);
dialog.setNeutralButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
}
});
dialog.show();
return true;
}
@Override
public void onLongPress(MotionEvent e)
{
long downTime = e.getDownTime();
System.out.println("Down time: " + downTime);
System.out.println("LongPress Registered");
GeoPoint p = localMapView.getProjection().fromPixels((int) e.getX(), (int) e.getY());
System.out.println("Latitude = " + p.getLatitudeE6() + " Longitude: " + p.getLongitudeE6());
}
Currently I have a series of markers on a google map. I want to be able to get the latitude and longitude from anywhere I longclick on the map and I want to open a message box dialog when I quick click on a marker. My issue is that by setting up longpress to work it makes it so my onTap function only gets called when I longclick. Is it possible for longlick to work only when I'm not clicking on a marker?
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
return gestureScanner.onTouchEvent(event);
//return false;
}
////////////////////////////////////
// Handle the clicking of a marker
//
////////////////////////////////////
@Override
protected boolean onTap(int index)
{
System.out.println("OnTap");
OverlayItem item = mOverlays.get(index);
int localLat = item.getPoint().getLatitudeE6();
int localLong = item.getPoint().getLongitudeE6();
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
// Get the titles
dialog.setTitle(item.getTitle());
// Get the text for the message
//dialog.setMessage(item.getSnippet());
dialog.setMessage("Latitude: " + localLat + "\nLongitude: " + localLong);
dialog.setNeutralButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
}
});
dialog.show();
return true;
}
@Override
public void onLongPress(MotionEvent e)
{
long downTime = e.getDownTime();
System.out.println("Down time: " + downTime);
System.out.println("LongPress Registered");
GeoPoint p = localMapView.getProjection().fromPixels((int) e.getX(), (int) e.getY());
System.out.println("Latitude = " + p.getLatitudeE6() + " Longitude: " + p.getLongitudeE6());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此处类似的内容可能会有所帮助。您还可以重写 Overlay 的
onTouchEvent()
来处理每个事件。Here's something similar here that might be helpful. You can also override the
onTouchEvent()
of the Overlay to handle each.