isaleem isaleem - 2 years ago 119
Objective-C Question

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.


Answer Source

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;
[ 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 = [ convertPoint:[gestureRecognizer]];

    [ setCenterCoordinate:coordinate animated:YES];

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download