Я создал кнопку в нижней панели. Когда пользователь нажимает кнопку, я пытаюсь показать UIAlertView, поэтому пользователь может ввести адрес, который приведет к отображению синего контакта на карте. Этот вывод затем должен быть сохранен в NSUserDefaults, чтобы местоположение сохранялось при каждом перезапуске приложения.Pin Аннотация с UIAlertView
Вот что у меня есть. Пользователь может ввести адрес в UIAlertView, но ничего не происходит ...
- (IBAction)selectHq:(UIBarButtonItem *)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Select Headquarters"
message:@"Enter Address"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
[alert show];
UITextField *field = [alert textFieldAtIndex:0];
field.placeholder = @"Enter HQ Address";
if (!self.geocoder)
{
self.geocoder = [[CLGeocoder alloc] init];
}
NSString *hqAddress = [NSString stringWithFormat:@"%@", field.text];
[self.geocoder geocodeAddressString:hqAddress completionHandler:^(NSArray *placemarks, NSError *error) {
if ([placemarks count] > 0)
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D hqCoordinate = location.coordinate;
NSLog (@"%f %f", hqCoordinate.latitude, hqCoordinate.longitude);
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.01;
region.span = span;
region.center = hqCoordinate;
MKPointAnnotation *hqAnnotation = [[MKPointAnnotation alloc] init];
[hqAnnotation setCoordinate:hqCoordinate];
[hqAnnotation setTitle:@"HQ"];
[[self mapView] addAnnotation:hqAnnotation];
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];
}
}];
[[NSUserDefaults standardUserDefaults] setObject:field.text forKey:HQ_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
Теперь он работает. Штифт фиолетовый. Как изменить цвет булавки на синий? –
@GeorgeFriday смотрите http://stackoverflow.com/questions/1185611/mkpinannotationview-are-there-more-than-three-colors-available. Это может вам помочь. –