Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Below is an example that creates a circle and drops a pin where the user touches and holds their finger for 1 second. It uses a UILongPressGestureRecognizer which is added to the mapView wherever the map is initialized (eg. viewDidLoad).</p> <p>Make sure the mapView's delegate is set also.</p> <pre><code>// In viewDidLoad or where map is initialized... UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; lpgr.minimumPressDuration = 1.0; //user must hold for 1 second [mapView addGestureRecognizer:lpgr]; [lpgr release]; ... - (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state != UIGestureRecognizerStateBegan) return; CGPoint touchPoint = [gestureRecognizer locationInView:mapView]; CLLocationCoordinate2D touchMapCoordinate = [mapView convertPoint:touchPoint toCoordinateFromView:mapView]; //add pin where user touched down... MKPointAnnotation *pa = [[MKPointAnnotation alloc] init]; pa.coordinate = touchMapCoordinate; pa.title = @"Hello"; [mapView addAnnotation:pa]; [pa release]; //add circle with 5km radius where user touched down... MKCircle *circle = [MKCircle circleWithCenterCoordinate:touchMapCoordinate radius:5000]; [mapView addOverlay:circle]; } -(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay { MKCircleView* circleView = [[[MKCircleView alloc] initWithOverlay:overlay] autorelease]; circleView.fillColor = [UIColor redColor]; return circleView; } - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation { static NSString *AnnotationIdentifier = @"Annotation"; MKPinAnnotationView* pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; if (!pinView) { pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease]; pinView.pinColor = MKPinAnnotationColorGreen; pinView.animatesDrop = YES; } else { pinView.annotation = annotation; } return pinView; } </code></pre>
 

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