1

MKPolylineを表示しようとしています。ほとんどすべてが正しいと思いますが、何かが足りないに違いありません。エラーコードはありません。それ以外の場合、マップは正常に表示され、注釈ピンを正常にドロップできます。

.h

@interface SatFinderViewController: UIViewController 
<MKMapViewDelegate>
{
IBOutlet MKOverlayView *mapView;
IBOutlet MKMapView *map;
MKMapView *_mapView;
MKPolyline *_routeLine;
MKPolylineView *_routeLineView;

}
@property (nonatomic, retain) IBOutlet MKMapView *map;
@property (nonatomic, retain) MKAnnotationView *mapAView;
@property (nonatomic, retain) MKOverlayView *mapView;
@property (nonatomic, retain) MKPolyline *routeLine;
@property (nonatomic, retain) MKPolylineView *routeLineView;

-(void)calculate;
-(void)loadRoute;

@end

彼ら

-(void)calculate
{ ...

[map removeOverlay:self.routeLine];
self.routeLine = nil;   
[self loadRoute];
[map addOverlay:routeLine];
[map setNeedsDisplay];

}

-(void) loadRoute
{
SatFinderAppDelegate *appdel = (SatFinderAppDelegate *)[[UIApplication sharedApplication]delegate];
float s = [appdel.location floatValue];

CLLocationCoordinate2D *locations = malloc(sizeof(CLLocationCoordinate2D) * 2);

CLLocationCoordinate2D satcoord = CLLocationCoordinate2DMake(0, s);
CLLocationCoordinate2D dishcoord = CLLocationCoordinate2DMake(pinlat, pinlon);

locations[0] = satcoord;
locations[1] = dishcoord;

NSLog(@"satcoord %f,%f", locations[0].latitude, locations[0].longitude);
NSLog(@"dishcord %f,%f", locations[1].latitude, locations[1].longitude);

// Create the polyline based on the array of points.   
routeLine = [MKPolyline polylineWithCoordinates:locations count:1];

[routeLineView setNeedsDisplay];

}
- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{

routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
routeLineView.fillColor = [UIColor blueColor];
routeLineView.strokeColor = [UIColor blueColor];
routeLineView.lineWidth = 5;
return routeLineView;

}
4

1 に答える 1

0
routeLine = [MKPolyline polylineWithCoordinates:locations count:1]; 

「count:1」ではなく「count:2」にする必要があります

于 2012-06-05T09:05:02.003 に答える