1

I was thinking of an application where user could select a location on an iphone app. I have googled it and didn't find anything useful.

My question is, is it possible to let the user select a location from an iphone app using MapKit/CLLocation? If yes, please help me where should i start.

Thanks

imrn
  • 297
  • 2
  • 12

2 Answers2

2

You can add a long press gesture recognizer to the map:

UILongPressGestureRecognizer* lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.5;
lpgr.delegate = self;
[self.map addGestureRecognizer:lpgr];
[lpgr release];

In the handle long press method get the CLLocationCordinate2D:

- (void) handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
    /*
     Only handle state as the touches began
     set the location of the annotation
     */

    CLLocationCoordinate2D coordinate = [self.map convertPoint:[gestureRecognizer locationInView:self.map] toCoordinateFromView:self.map];

    [self.map setCenterCoordinate:coordinate animated:YES];

  // Do anything else with the coordinate as you see fit in your application

   }
}
nimeshdesai
  • 487
  • 1
  • 5
  • 10
0

Take a look at this SO answer. The answer tells you not only how to get the coordinate, but also how to put a pin (annotation) on the map.

Community
  • 1
  • 1
Jim
  • 5,940
  • 9
  • 44
  • 91