Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add event listener to the MyLocationOverlay? #536

Closed
zhaoxuhui opened this issue Jan 13, 2017 · 5 comments
Closed

How to add event listener to the MyLocationOverlay? #536

zhaoxuhui opened this issue Jan 13, 2017 · 5 comments
Milestone

Comments

@zhaoxuhui
Copy link

How to show a menu or a pop window that conatains some buttons when I click the icon?So that I can do futher things.
324403370story_pic_merged_1484305803549

@spyhunter99
Copy link
Collaborator

i think you can override on single tap confirmed but i'm not sure if there's a clear example on doing this at the moment. I'd suggest extending the MyLocationOverlay and going from there. The other option is to just use the Marker class to plot my location, however you'll lose the gps accuracy ring and the directional locator.

@spyhunter99
Copy link
Collaborator

extend MyLocationNewOverlay and add this

@Override
	public boolean onSingleTapConfirmed(MotionEvent e, MapView map) {
		if (getLastFix() != null)
			Toast.makeText(map.getContext(), "Tap! I am at " + getLastFix().getLatitude() + "," + getLastFix().getLongitude(), Toast.LENGTH_LONG).show();
		return true;

	}

@spyhunter99
Copy link
Collaborator

sample added and pushed.

@spyhunter99 spyhunter99 added this to the v5.6.3 milestone Jan 14, 2017
@cfsbhawkins
Copy link
Contributor

@spyhunter99 Just as a heads up, make sure you had the hit test method thats in marker, if not the you can touch anywhere on the map and it will fire that event.

public boolean hitTest(final MotionEvent event, final MapView mapView){
final Projection pj = mapView.getProjection();
pj.toPixels(mPosition, mPositionPixels);
final Rect screenRect = pj.getIntrinsicScreenRect();
int x = -mPositionPixels.x + screenRect.left + (int) event.getX();
int y = -mPositionPixels.y + screenRect.top + (int) event.getY();
boolean hit = mIcon.getBounds().contains(x, y);
return hit;
}

@Override public boolean onSingleTapConfirmed(final MotionEvent event, final MapView mapView){
	boolean touched = hitTest(event, mapView);
	if (touched){
		if (mOnMarkerClickListener == null){
			return onMarkerClickDefault(this, mapView);
		} else {
			return mOnMarkerClickListener.onMarkerClick(this, mapView);
		}
	} else
		return touched;
}

@cfsbhawkins
Copy link
Contributor

Something like this for the hit test works....

public boolean hitTest(final MotionEvent event, final MapView mapView) {
if ((mLocation == null)) return false;
Rect bounds = getMyLocationDrawingBounds(mapView.getZoomLevel(), mLocation,
mMyLocationPreviousRect);
boolean hit = bounds.contains((int)event.getX(),(int) event.getY());
bounds = null;
return hit;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants