简体   繁体   English

MKPolyline不会显示

[英]MKPolyline won't display

I'm trying to get my MKPolyline to display, I think I have most everything right, but I must be missing something. 我想让我的MKPolyline显示,我想我几乎所有的东西都对,但是我肯定缺少一些东西。 No error codes, the map displays fine otherwise and I can drop annotation pins just fine. 没有错误代码,地图显示正常,否则我可以删除注释图钉。

the .h .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

The .m .m

-(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;

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

应该是“ count:2”而不是“ count:1”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM