objective-c - MKPolyline 不会显示

标签 objective-c ios mapkit

我正在尝试让我的 MKPolyline 显示出来,我想我几乎一切都正确,但我一定遗漏了一些东西。没有错误代码,否则 map 显示正常,我可以放下注释图钉。

.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

.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”

关于objective-c - MKPolyline 不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10860333/

相关文章:

Swift 异步函数滞后

ios - 如何在mapVIew中添加多重标注

iphone - 动画 GIF 图像作为 iphone 中的启动画面

ios - 如何在 iOS 中读取、写入和检查不区分大小写的文件名?

objective-c - 调整 NSCollectionView 的大小以适应内部项目?

ios - 传递 NSManagedObjectContext 的实例

ios - Swift - 使用 tableView 的大标题过渡

ios - 使用 UIImage imageNamed : @"cardback" 时无法获取对象

ios - 将MKTileOverlay与MKPolyLine一起使用

iphone - 如何在iphone中实现下拉框?