Im trying to figure out how to put an annotation on a map based on where the user touches.
I have tried subclassing the MKMapView and looked for the touchesBegan to fire but as it turns out, MKMapView does not use the standard touches methods.
I also have tried subclassing a UIView, adding an MKMapView as a child and then listening for HitTest and touchesBegan. This works somewhat. if i have my map the full size of the uiview, then have something like this
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
return map;
}
and that works, my touchesBegan will be able to get the point using
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches){
CGPoint pt = [touch locationInView:map];
CLLocationCoordinate2D coord= [map convertPoint:pt toCoordinateFromView:map];
NSLog([NSString stringWithFormat:@"x=%f y=%f - lat=%f long = %f",pt.x,pt.y,coord.latitude,coord.longitude]);
}
}
but then the map has some crazy behavior like it will not scroll, and it will not zoom in unless double tapped but you can zoom out. and it only works if i return the map as the view. If i do not have the hit test method, the map works fine but obviously doesnt get any data.
Am i going about getting the coordinate wrong? Please tell me there is a better way. I know how to add annotations just fine, i just cannot find any examples of adding an annotation where and when a user touches the map.