Ios 多段线不工作
我试图从两个纬度和经度数组中重新创建一条多段线 但是,当我开始构建多段线时,地图上没有显示任何内容,我不知道为什么 以下是我的代码:Ios 多段线不工作,ios,objective-c,mkpolyline,Ios,Objective C,Mkpolyline,我试图从两个纬度和经度数组中重新创建一条多段线 但是,当我开始构建多段线时,地图上没有显示任何内容,我不知道为什么 以下是我的代码: CLLocationCoordinate2D coordinates[[_longitudeArray count]]; for (int i = 0; i < [_longitudeArray count]; i++) { CLLocationCoordinate2D coordinate; double l
CLLocationCoordinate2D coordinates[[_longitudeArray count]];
for (int i = 0; i < [_longitudeArray count]; i++) {
CLLocationCoordinate2D coordinate;
double latitude = [[_latitudeArray objectAtIndex:i] doubleValue];
NSLog(@"latitude = %f", latitude);
double longitude = [[_longitudeArray objectAtIndex:i] doubleValue];
coordinate.latitude = latitude;
coordinate.longitude = longitude;
coordinates[i] = coordinate;
}
MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:[_longitudeArray count]];
[_mapView addOverlay:polyLine];
[_mapView setVisibleMapRect:polyLine.boundingMapRect animated:YES];
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]])
{
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:overlay];
[self.mapView setVisibleMapRect:overlay.boundingMapRect animated:YES];
renderer.strokeColor = [[UIColor redColor] colorWithAlphaComponent:0.7];
renderer.lineWidth = 3;
return renderer;
}
return nil;
}
CLLocationCoordinate2D坐标[[u longitudarray count]];
对于(int i=0;i<[u longitudarray count];i++){
CLLocationCoordinate2D坐标;
双纬度=[[u latitudarray objectAtIndex:i]双值];
NSLog(@“纬度=%f”,纬度);
双经度=[[u longitudaray objectAtIndex:i]doubleValue];
坐标。纬度=纬度;
坐标经度=经度;
坐标[i]=坐标;
}
MKPolyline*polyLine=[MKPolyline polyLine with coordinates:坐标计数:[[u longitudarray count]];
[_MapViewAddOverlay:多段线];
[_MapViewSetVisibleMaprect:polyLine.boundingMapRect动画:是];
}
-(MKOverlayRenderer*)地图视图:(MKMapView*)地图视图渲染器ForOverlay:(id)overlay
{
if([overlay iskindof类:[MKPolyline类]])
{
MKPolylineRenderer*渲染器=[[MKPolylineRenderer alloc]initWithPolyline:overlay];
[self.mapView setVisibleMapRect:overlay.boundingMapRect-animated:YES];
renderer.strokeColor=[[UIColor redColor]colorWithAlphaComponent:0.7];
1.lineWidth=3;
返回渲染器;
}
返回零;
}
你知道我哪里出错了吗?你的
NSLog
打印了什么?对不起,我太傻了!!我的地图视图未连接。谢谢你,问题很简单。但是,请确保从rendererForOverlay中删除对setVisibleMapRect的调用——您不需要它,并且可能会导致性能问题。@user3254994很高兴您解决了问题!不过,我可能会建议你继续删除这个问题。