Note that there are some explanatory texts on larger screens.

plurals
  1. POGet the coordinates of a point from mkmapview on iphone
    primarykey
    data
    text
    <p>I'm trying to figure out how to put an annotation on a map based on where the user touches. </p> <p>I have tried sub-classing the <code>MKMapView</code> and looked for the <code>touchesBegan</code> to fire but as it turns out, <code>MKMapView</code> does not use the standard <em>touches</em> methods.</p> <p>I also have tried sub-classing a <code>UIView</code>, adding an <code>MKMapView</code> as a child and then listening for HitTest and <code>touchesBegan</code>. This works somewhat. if i have my map the full size of the <code>UIView</code>, then have something like this </p> <pre><code>- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { return map; } </code></pre> <p>and that works, my <code>touchesBegan</code> will be able to get the point using </p> <pre><code>- (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]); } } </code></pre> <p>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 doesn't get any data.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload