3

何よりもまず、英語が下手で申し訳ありません。

UIView でルートを描画し、そのビューを MKMapView として設定しようとしています。

今、私は UIView クラス (ViewClass) を持っています。ここにすべての touches メソッドを配置し、viewcontroller のビューをそのクラスのインスタンスとして設定します。MKMapView は、viewcontroller.view サブビューです。MKMapView ですべてのタッチを取得できます。トレイルを描画するには、UIView (trailView) を MKMapView サブビューとして設定し、背景色をクリアします。MKMapView が移動しているときに TrailView を移動しようとしましたが、良い結果が得られません。移動が完全ではありません。

アイデアは、ビューを MKMapView にアタッチすることです。それが可能かどうか、または本当に MKAnnotationView を使用する必要があるかどうかはわかりません。以前に MKAnnotationView を試したことがありますが、それは多くのメモリを消費します。

助けていただければ幸いです。前もって感謝します。

4

3 に答える 3

1

iOS4には、パスのレンダリングを含む新しいオーバーレイシステムがあります。まだ使用していませんが、独自のオーバーレイをロールするよりもはるかに簡単なようです。

http://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKOverlayPathView_class/Reference/Reference.html#//apple_ref/doc/uid/TP40009713を参照してください

于 2010-06-25T13:34:11.320 に答える
0

これはとても良い質問です。

関心のあるマップの領域からピクセル データを取得し、パスの色に基づいて最近傍計算を行うのはどうでしょうか。あなたが探している方向に。このパスを保存して、trailView に別の色をレンダリングしますか?

これをさらに複雑にしているのはズームです。これは、ピクセル座標ではなく、解像度に依存しないトレイル (マップ座標を変換する) が必要になるためです。したがって、ピクセル座標をマップ座標に変換すると、ズーム用にスケーリングする必要があります。

于 2010-01-20T18:40:23.380 に答える
0

トレイルは並んでいますが、スクロールすると悪い結果が得られます。MKAnnotatioView を使用したアプリのバージョンに関しては、コードを表示できますが、ログを表示することはできません。残念ながら、現在 iPhone を使用していないためです...

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {  

self.startingPoint = newLocation;

CLLocation *lastLocation;

if([pointArray count] >= 2)
{
    lastLocation = [pointArray objectAtIndex:1];
    [pointArray removeAllObjects];
}       

mapView.showsUserLocation = NO;

double lat,lon;     
lat = newLocation.coordinate.latitude;
lon = newLocation.coordinate.longitude;         

if(distanceIndex == 0)
{
    [pointArray insertObject:newLocation atIndex:0];
}
else 
{               
    if(distanceIndex == 1)
    {
        [pointArray insertObject:newLocation atIndex:1];
    }
    else 
    {
        [pointArray insertObject:lastLocation atIndex:0];
        [pointArray insertObject:newLocation atIndex:1];
    }
}           

if(distanceIndex == 0)
{
    MarkPlace *mark = nil;  

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateStyle:NSDateFormatterNoStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];     
    NSString *dateStr = [dateFormatter stringFromDate:[NSDate date]];
    [dateFormatter release];
    NSString *subtitle = [NSString stringWithFormat:@"Time Here: %@", dateStr];
    mark = [[[MarkPlace alloc] initWithCoordinate:[[pointArray objectAtIndex:0] coordinate] currentTime:subtitle annotationType:MarkPlaceTypeEnd title:@"Pin Title"] autorelease];
    [mapView addAnnotation:mark];




}

//create the route
MKCoordinateSpan span = mapView.region.span;
CLLocationCoordinate2D center = mapView.region.center;

IFRouteAnnotations *routeAnnotation = [[[IFRouteAnnotations alloc] initWithPoints:pointArray:0:span:center] autorelease];
[mapView addAnnotation:routeAnnotation];

[mapView setRegion:routeAnnotation.region animated:TRUE];

distanceIndex = distanceIndex + 1;
[routeAnnotation release];

}

    -(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
//re-enable and re-position the route display
for (NSObject *key in [routeViews allKeys]) {
    IFRouteView *routeView = [routeViews objectForKey:key];
    [routeView regionChanged];
}

}

-(MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id <MKAnnotation>)annotation{

MKAnnotationView *annotationView = nil;
NSLog(@"viewForAnnotation");
if(distanceIndex == 0)
{       
    MKPinAnnotationView *pin=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"] autorelease];
    pin.pinColor = MKPinAnnotationColorGreen;
    pin.animatesDrop = TRUE;
    pin.userInteractionEnabled = YES;

    annotationView = pin;
    [annotationView setEnabled:YES];
    [annotationView setCanShowCallout:YES];
}

if([annotation isKindOfClass:[IFRouteAnnotations class]])
{
    IFRouteAnnotations *routeAnnotation = (IFRouteAnnotations *)annotation;

    annotationView = [routeViews objectForKey:routeAnnotation.routeID];

    if(annotationView == nil)
    {
        IFRouteView *routeView = [[[IFRouteView alloc] initWithFrame:CGRectMake(0,0, mapView.frame.size.width, mapView.frame.size.height)]autorelease];

        routeView.annotation = routeAnnotation;
        routeView.mapView = mapView;

        [routeViews setObject:routeView forKey:routeAnnotation.routeID];

        annotationView = routeView;
    }
}   
return annotationView;

}

あなたが何かを理解するかどうかはわかりません。私のコードはlink textに基づいています。ご協力いただきありがとうございます!!:)

于 2010-01-21T15:59:20.660 に答える