Issue
I am using a MapView (google's) and add some overlays onto it. I use my own overlay class which looks like this:
public class MyOverlay extends ItemizedOverlay<OverlayItem>
When I zoom out and cause all my items to be at the same location and tap the image, I get onTap event for only 1 out of all the items ehich are at the tapped location.
I want to be able to get onTap event for each and every item which is under the location on the map which I tap on, or either an ability to ask the map for all items at a specific rectangle where I press.
this is my code for debugging:
@Override
protected boolean onTap(int i)
{
super.onTap(i);
return false;
}
and get only 1 tap for each overlay.
Is it possible? how?
Thanks.
Solution
One way is this: (Note that this is pseudo code)
// Over ride the onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event, final MapView mapView) {
final int action=event.getAction();
final int x = (int)event.getX();
final int y = (int)event.getY();
if (action == MotionEvent.ACTION_DOWN) {
// get the zoom level
zoomLevel = mapView.getZoomLevel();
if(zoomLevel > appropriateZoom)
{
if(items != null) {
for(int i = 0; i < items.size(); i++){
OverlayItem item = items.get(i);
Point mp = new Point(0,0);
mapView.getProjection().toPixels(item.getPoint(), mp);
xDragTouchOffset=x-mp.x;
yDragTouchOffset=y-mp.y;
if (hitTest(item, marker, x-(mp.x-(xDragImageOffset+xDragTouchOffset*2)), y-(mp.y-((yDragImageOffset/2)+yDragTouchOffset)))) {
// This item has been tapped. Do what you want here.
}
}
This is only a idea/hint to get you started.
Answered By - Reno
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.