Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c MKMapView的多段线不工作_Objective C_Mkmapview_Mkpolyline - Fatal编程技术网

Objective c MKMapView的多段线不工作

Objective c MKMapView的多段线不工作,objective-c,mkmapview,mkpolyline,Objective C,Mkmapview,Mkpolyline,我一直在努力让这条多边形线在Objective C中工作。我已经阅读了所有我能找到的教程,但都一无所获,我看不出它有什么问题 CLLocationCoordinate2D coordinateArray2[2]; coordinateArray2[1].longitude = 176.8773669; coordinateArray2[0].longitude = 176.88151896; coordinateArray2[0].latitude = -39.668593; coor

我一直在努力让这条多边形线在Objective C中工作。我已经阅读了所有我能找到的教程,但都一无所获,我看不出它有什么问题

    CLLocationCoordinate2D coordinateArray2[2]; 
coordinateArray2[1].longitude = 176.8773669;
coordinateArray2[0].longitude = 176.88151896;
coordinateArray2[0].latitude = -39.668593;
coordinateArray2[1].latitude = -39.67018069;
_route1Line = [MKPolyline polylineWithCoordinates:coordinateArray2 count:2]; 
[_GPSView setDelegate:self];
[_GPSView addOverlay:_route1Line];
_testlabel.text = [NSString stringWithFormat:@"%f", coordinateArray2[0].longitude];
有人能看出哪里出了问题吗

标题:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>


extern int routenumber; //holds current route ID

extern BOOL inRoute; //holds if on route or not

extern int followYou; //holds if the app should follow the user or predefined coordinates

extern NSArray *routeHolder; //holds array of routes

@interface ViewController : UIViewController <MKMapViewDelegate>

@property (weak, nonatomic) IBOutlet MKMapView *GPSView; //adding the map view to the controller

@property (nonatomic, retain) MKPolyline *route1Line; //line for this route

@property (weak, nonatomic) IBOutlet UILabel *testlabel;

@end
#导入
#进口
外部-内部路由//保存当前路由ID
在路线上的外部布尔//是否在路线上保持
外部跟随你//如果应用程序应遵循用户坐标或预定义坐标,则保持不变
外线*线路管理员//保存路由数组
@界面ViewController:UIViewController
@属性(弱、非原子)IBMMapView*GPSView//将地图视图添加到控制器
@属性(非原子,保留)MKPolyline*route1Line//这条路线的线路
@属性(弱、非原子)IBUILabel*testlabel;
@结束

我现在不在Mac电脑上,因此无法运行您的代码,但看起来您已经创建了MKPolyline,但您缺少了MKPolyline视图

_polylineView = [MKPolylineView alloc] initWithPolyline:route1Line]; // Declare it in your header file or in the implementation's interface.
_polylineView.strokeColor = [UIColor redColor];
_polylineView.lineWidth = 5.0
然后确保您符合MKMapViewDelegate并实现mapView:viewForOverlay

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay {
    return _polylineView;
}
-(MKOverlayView*)地图视图:(MKMapView*)地图视图覆盖:(id)覆盖{
返回多段线视图;
}

您应该实现以下方法
MKMapViewDelegate

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
    MKOverlayPathRenderer *theOverlayPathRenderer;
    {
        theOverlayPathRenderer = [[MKPolylineRenderer alloc] initWithPolyline:overlay];
        theOverlayPathRenderer.lineWidth = ...;
        theOverlayPathRenderer.fillColor = ...;
        theOverlayPathRenderer.strokeColor = ...;
    }
    return theOverlayPathRenderer;
}
-(mkoverlayrender*)地图视图:(MKMapView*)地图视图渲染器foroverlay:(id)overlay
{
MKOverlayPathRenderer*OverlayPathRenderer;
{
OverlayPathRenderer=[[MKPolylineRenderer alloc]initWithPolyline:overlay];
theOverlayPathRenderer.lineWidth=。。。;
theOverlayPathRenderer.fillColor=。。。;
theOverlayPathRenderer.strokeColor=。。。;
}
返回OverlayPathRenderer;
}

抱歉,忽略注释如果您建议使用不推荐的方法,最好查看我的答案