d0ping / DBMapSelectorViewController

This component allows you to select circular map region from the MKMapView.
MIT License
323 stars 36 forks source link

Touch recognition #9

Closed bharathi91 closed 8 years ago

bharathi91 commented 9 years ago

How can i add touch recognition for the circle. As of now im getting touch events for long press any where on the mapView. I need to get get touches on the circle view. Can you please explain?

d0ping commented 9 years ago

Yes, it's right. MapView handle gestures on the circle because circle selector it's part of the map. You should manually define where was make touch. I'm wrote small method for handle tap gesture on the map...

- (void)tapOnMapGestureRecognizer:(UITapGestureRecognizer *)recognizer {
    CGPoint touchPoint = [recognizer locationInView:self.mapView];
    CLLocationCoordinate2D coord = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
    CLLocation *touchLocation = [[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude];
    CLLocation *selectorCenterLocation = [[CLLocation alloc] initWithLatitude:self.mapSelectorManager.circleCoordinate.latitude longitude:self.mapSelectorManager.circleCoordinate.longitude];
    CLLocationDistance dist = [touchLocation distanceFromLocation:selectorCenterLocation];
    NSLog(@"%@ %.2f", (dist <= self.mapSelectorManager.circleRadius ) ? @"Y" : @"N", (float)dist);
}

Did it help you solve your problem?

bharathi91 commented 9 years ago

Thank you . I will try it and let you know the results.