これはどのように動作するのですか?私は文字列の値に基づいてピンをドロップするCLGeocoderを作成しています。私はこれを持っています:MKPinAnnotationViewをアニメーションでドロップする
- (void)placeMarkFromString:(NSString *)address {
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
[placemarks enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(@"%@", [obj description]);
}];
// Check for returned placemarks
if (placemarks && [placemarks count] > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
// Create an MKPlacemark and add it to the mapView
MKPlacemark *place = [[MKPlacemark alloc] initWithPlacemark:topResult];
AddressAnnotation *anAddress = [[AddressAnnotation alloc] init];
anAddress.address = place.subThoroughfare;
anAddress.street = place.thoroughfare;
anAddress.city = place.locality;
anAddress.state = place.administrativeArea;
anAddress.zip = place.postalCode;
anAddress.name = place.name;
//[self.mapView addAnnotation:place];
[self.mapView addAnnotation:anAddress];
self.currentPlacemark = place;
// Center map on that region
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(topResult.location.coordinate, 2000, 2000);
MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:region];
[_mapView setRegion:adjustedRegion animated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Results Found" message:@"" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}
if (error) {
NSLog(@"Error: %@", [error localizedDescription]);
}
}];
}
元々、私はMKPlacemarkをマップに追加して、赤いピンを表示しました。しかし、アニメーション化されません。私は基本的に、3つのMKPinAnnotationViewの色を落とし、コールアウトとタイトル/サブタイトルを場所の名前と住所にする機能を望んでいます。これはGoogleマップと同様です。しかし、私はアニメーションを取得していませんでした。
私はMKAnnotationクラスに準拠した独自のオブジェクトを作成する必要があると考えました。だから、私はそれをしましたが、場所に追加しようとすると、viewForAnnotationデリゲートメソッドでそのannotationViewが表示されません。その方法はここにある:
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id<MKAnnotation>)annotation {
static NSString *placeMarkIdentifier = @"SimplePinIdentifier";
if ([annotation isKindOfClass:[AddressAnnotation class]]) {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:placeMarkIdentifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:placeMarkIdentifier];
}
else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.animatesDrop = YES;
annotationView.draggable = YES;
annotationView.pinColor = MKPinAnnotationColorPurple;
annotationView.canShowCallout = YES;
// Create a button for the annotation
// UIButton *rightArrowButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// annotationView.rightCalloutAccessoryView = rightArrowButton;
// [self performSelector:@selector(openCallout:) withObject:annotation afterDelay:0.5];
return annotationView;
}
return nil;
}
だから私は、私は、これを行うには自分自身のオブジェクトを作成する必要があり、私は正しい軌道に乗っています、私が間違って何をやっている、そしてなぜそれがでていることであるか、私の質問があると思いますあるケースでは、MKPlacemarkオブジェクトを追加しています。それを他の方法で行うと、オブジェクトを追加しますが、必ずしもMKPlacemarkのサブクラスではありません。ありがとう!