imrn
imrn

Reputation: 307

Selecting Location from MapView

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

Upvotes: 1

Views: 5272

Answers (2)

Jim
Jim

Reputation: 5960

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.

Upvotes: 0

nimeshdesai
nimeshdesai

Reputation: 487

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

   }
}

Upvotes: 2

Related Questions