アップデート
この問題はiOS4.3で静かに修正されたようです。この時点まで、注釈をリサイクルするのに「十分に遠い」と見なされた距離は、非常に近くにズームインした場合でも、数百マイルのように見えました。iOS 4.3 SDKを使用してアプリをビルドすると、より妥当な制限に基づいてアノテーションがリサイクルされます。
他の誰かがこの問題に遭遇しましたか?コードは次のとおりです。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(WWMapAnnotation *)annotation {
// Only return an Annotation view for the placemarks. Ignore for the current location--the iPhone SDK will place a blue ball there.
NSLog(@"Request for annotation view");
if ([annotation isKindOfClass:[WWMapAnnotation class]]){
MKPinAnnotationView *browse_map_annot_view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"BrowseMapAnnot"];
if (!browse_map_annot_view) {
browse_map_annot_view = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"BrowseMapAnnot"] autorelease];
NSLog(@"Creating new annotation view");
} else {
NSLog(@"Recycling annotation view");
browse_map_annot_view.annotation = annotation;
}
..。
ビューが表示されるとすぐに、
2009-08-05 13:12:03.332 xxx[24308:20b] Request for annotation view
2009-08-05 13:12:03.333 xxx[24308:20b] Creating new annotation view
2009-08-05 13:12:03.333 xxx[24308:20b] Request for annotation view
2009-08-05 13:12:03.333 xxx[24308:20b] Creating new annotation view
そして、私が追加したすべての注釈(〜60)に対して、何度も繰り返します。マップは(正しく)現在の四角形の2つの注釈のみを表示します。viewDidLoadでリージョンを設定しています:
if (center_point.latitude == 0) {
center_point.latitude = 35.785098;
center_point.longitude = -78.669899;
}
if (map_span.latitudeDelta == 0) {
map_span.latitudeDelta = .001;
map_span.longitudeDelta = .001;
}
map_region.center = center_point;
map_region.span = map_span;
NSLog(@"Setting initial map center and region");
[browse_map_view setRegion:map_region animated:NO];
注釈ビューが要求される前に、設定されている領域のログエントリがコンソールに出力されます。
ここでの問題は、すべての注釈が一度に要求されているため、[mapView dequeueReusableAnnotationViewWithIdentifier]は何もしないことです。これは、マップ上のすべての注釈に一意のMKAnnotationViewsがあるためです。これは私にとって記憶の問題につながります。
考えられる問題の1つは、これらの注釈が非常に小さなスペース(半径約1マイル)にクラスター化されていることです。マップはviewDidLoad(緯度と経度のデルタ.001)でかなりタイトにズームインされますが、それでもすべての注釈ビューを一度にロードします。
ありがとう...