これは私を狂わせています。私はstackoveflowのすべての投稿を確認しましたが、法案に適合するものはありません。にオーバーレイとして単純なポリライン(つまり、カスタムオーバーレイではない)を追加しようとしていMKMapView
ます。viewForOverlay
デリゲートのメソッドが呼び出されることはありません。マップデリゲートは、他のすべてのデリゲート関数に対して正しく呼び出されます。viewForOverlay
メソッドのコードは次のとおりです。
//maanges the overlay
- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay{
NSLog(@"does it ask for the overlay view?");
MKOverlayView *overlayView = nil;
return overlayView;
}
ポリラインを作成してマップに追加するコードは次のとおりです。
MKPolyline *thePolyline = [MKPolyline polylineWithPoints:pts count:[arrOfPoints count]];
[thePolyline setTitle:@"line"];
[mapView addOverlay:thePolyline];
ポリラインには実際に私のポイントのコレクション(約1000)があるので、問題はないと思います。マップビューに必要なプロパティやその他の実装がありませんか?
EDITポリラインMKMapPoint
生成のコードを表示します。
appConfigプロセスの一部としてポリラインを生成するために、約1100ポイントのxmlファイルを使用します。とを使用してファイルを読み取り、解析しNSXMLParser
ますNSXMLParserDelegate
。(プロトコルのfoundCharacters
メソッドから)ポイントを生成するコードは次のとおりです。NSXMLParserDelegate
//NSXMLParserDelegate methods...
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if(POINT){
NSArray *arr = [string componentsSeparatedByString:@","];
MKMapPoint pt = MKMapPointMake([[arr objectAtIndex:1]doubleValue], [[arr objectAtIndex:0]doubleValue]);
MapPointObject *thePoint = [[MapPointObject alloc] init];
thePoint.mapPoint = pt;
//gives the mkmappoint to the array of points.
[arrOfPoints addObject:thePoint];
[thePoint release];
}
}
ここに、ポイントが実際にを生成し、MKPolyline
それをmapViewに(プロトコルのdidEndElement
メソッドから)提供する場所があります。NSXMLParserDelegate
if([elementName isEqualToString:@"appConfig"]){
MKMapPoint *pts = malloc([arrOfPoints count] * sizeof(MKMapPoint));
for(int i = 0; i <= [arrOfPoints count] - 1; i++){
MapPointObject *pointObject = [arrOfPoints objectAtIndex:i];
pts[i] = pointObject.mapPoint;
}
MKPolyline *thePolyline = [MKPolyline polylineWithPoints:pts count:[arrOfPoints count]];
[thePolyline setTitle:@"line"];
//adding the polyline to the model's mapview
Model *theModel = [Model sharedModel];
[theModel.mapView setVisibleMapRect:thePolyline.boundingMapRect animated:YES];
[theModel.mapView addOverlay:thePolyline];
free(pts);
}
のポイントカウントプロパティMKPolyline
は、実際には1100ポイントあることを示しています。
編集:サンプルXML値:
<appConfig>
<point>-94.847587,38.977967</point>
<point>-94.844111,38.977978</point>
<point>-94.844108,38.977369</point>
<point>-94.844003,38.977369</point>
<point>-94.843955,38.974886</point>