我混淆了这项工作的方式。 I m 创建CLGeocoder,以根据扼杀性价值推卸胎。 我有:
- (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,显示红pin。 然而,这并非偶然。 我基本上希望能够放弃3个MKPinAnnotationView的颜色中的任何一种,拥有一个叫.,并拥有名称/称号,即该地点的名称和地址,类似于Google地图。 但是,我没有看到任何悲观。
因此,我认为,也许我需要创建符合MKAnnotation等级的我自己的物体。 因此,我这样做了,但当我试图将其添加到该地点时,我看不出它的含义。 观点代表方法。 这种方法在这里是:
- (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的子级。 感谢!