Last active
December 17, 2015 04:38
-
-
Save christopherhouse/5551818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SetupGestureRecognizer() | |
{ | |
this.MapView.AddGestureRecognizer(new UITapGestureRecognizer(r => { | |
PointF pointInView = r.LocationInView(this.MapView); | |
CLLocationCoordinate2D touchCoordinates = this.MapView.ConvertPoint(pointInView, this.MapView); | |
MKMapPoint mapPoint = MKMapPoint.FromCoordinate(touchCoordinates); | |
foreach (NSObject overlay in this.MapView.Overlays) | |
{ | |
if (overlay is MKPolygon) | |
{ | |
MKPolygon polygon = (MKPolygon)overlay; | |
MonoTouch.MapKit.MKOverlayView view = this.MapView.ViewForOverlay(polygon); | |
if (view is MKPolygonView) | |
{ | |
MKPolygonView polygonView = (MKPolygonView)view; | |
PointF polygonViewPoint = polygonView.PointForMapPoint(mapPoint); | |
bool isInView = polygonView.Path.ContainsPoint(polygonViewPoint, false); | |
if (isInView) | |
{ | |
string message = string.Concat("You tapped ", polygon.Title); | |
UIAlertView alertView = new UIAlertView("Tap recognized!", message, null, "OK"); | |
alertView.Show (); | |
} | |
} | |
} | |
} | |
})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment