Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

6_Location

.pdf
Скачиваний:
3
Добавлен:
17.03.2016
Размер:
902.94 Кб
Скачать

Marking Your Annotation View as Draggable

Annotation views provide built-in dragging support, which makes it very easy to drag annotations around the map and to ensure that the annotation data is updated accordingly. To implement minimal support for dragging:

-In your annotation objects, implement the setCoordinate: method to allow the map view to update the annotation’s coordinate point.

-When creating your annotation view, set its draggable property to YES.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState

fromOldState:(MKAnnotationViewDragState)oldState;

Add annotation on Map tap

UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapClicked:)];

singleTapRecognizer.numberOfTapsRequired = 1; singleTapRecognizer.delegate = self;

[self.mapView addGestureRecognizer:singleTapRecognizer];

UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

{

if ([touch.view isKindOfClass:[MKMapView class]])

{

return YES;

}

return NO;

}

-(IBAction)mapClicked:(UITapGestureRecognizer *)recognizer

{

CGPoint point = [recognizer locationInView:self.mapView];

CLLocationCoordinate2D tapPoint = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];

SomeAnnotation * annotation = [[SomeAnnotation alloc] initWithCoordinate:tapPoint];

[self.mapView addAnnotation:annotation];

}

Geocoding Location

Data

About Geocoder Objects

Location data is usually returned as a pair of numerical values that represent the latitude and longitude of the corresponding point on the globe. These coordinates offer a precise and easy way to specify location data in your code but they aren’t very intuitive for users. Instead of global coordinates, users are more likely to understand a location that is specified using information they are more familiar with such as street, city, state, and country information. For situations where you want to display a user friendly version of a location, you can use a geocoder object to get that information.

Reverse geocoding

Note: The same CLGeocoder object can be used to initiate any number of geocoding requests but only one request at a time may be active for a given geocoder.

- (void)geocodeLocation:(CLLocation*)location forAnnotation:(MapLocation*)annotation

{

if (!geocoder)

geocoder = [[CLGeocoder alloc] init];

[geocoder reverseGeocodeLocation:location completionHandler: ^(NSArray* placemarks, NSError* error){

if ([placemarks count] > 0)

{

annotation.placemark = [placemarks objectAtIndex:0]; //CLPlacemark

// placemark.addressDictionary

}

}];

}

Converting Place Names Into Coordinates

[geocoder geocodeAddressString:@"1 Infinite Loop" completionHandler:^(NSArray* placemarks, NSError* error){

for (CLPlacemark* aPlacemark in placemarks)

{

// Process the placemark.

}

}];

Home Work

Add a UIButton to the Party Edit Screen Button opens a new Controller with map

User's current location is shown on map by an Annotation User can choose other location by click on a Map

Map shows address of location on a callout view in a subtitle value User can move this annotation by dragging

Annotation should have a button to choose this location for a party