Get the coordinates of a point from mkmapview on iphone

前端 未结 5 1431
夕颜
夕颜 2020-12-08 22:36

I\'m trying to figure out how to put an annotation on a map based on where the user touches.

I have tried sub-classing the MKMapView and looked for the

5条回答
  •  隐瞒了意图╮
    2020-12-08 22:56

    so i found a way to do it, finally. If i create a view and add a map object to it with the same frame. then listen for hit test on that view, i can call convertPoint:toCoordinateFromView: on the touch point sent, and give it the map like so:

    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
        CLLocationCoordinate2D coord= [map convertPoint:point toCoordinateFromView:map];
        NSLog(@"lat  %f",coord.latitude);
        NSLog(@"long %f",coord.longitude);
    
        ... add annotation ...
    
        return [super hitTest:point withEvent:event];
    }
    

    this is pretty rough as is and as you scroll the map it still constantly calls hit test so you will need to handle that, but its a start at getting the gps coordinates from touching a map.

提交回复
热议问题