我正在实现一个iOS应用程序,并且我想在地图上的几个给定坐标之间绘制折线。在地图上给定点之间绘制折线
我写了代码,得到了从我的点到达无限点的多段线。换句话说,线的起始点从我给定的经纬线开始,但线的终点是无限的,而不是另一点。
这是我的代码...
我填写的坐标在一个名为routeLatitudes
NSMutableArray
。阵列单元正在填充一个纬度和一个经度。
MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * [routeLatitudes count]);
for(int idx = 0; idx < [routeLatitudes count]; idx=idx+2)
{
CLLocationCoordinate2D workingCoordinate;
workingCoordinate.latitude=[[routeLatitudes objectAtIndex:idx] doubleValue];
workingCoordinate.longitude=[[routeLatitudes objectAtIndex:idx+1] doubleValue];
MKMapPoint point = MKMapPointForCoordinate(workingCoordinate);
pointArr[idx] = point;
}
// create the polyline based on the array of points.
routeLine = [MKPolyline polylineWithPoints:pointArr count:[routeLatitudes count]];
[mapView addOverlay:self.routeLine];
free(pointArr);
和覆盖委托
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
if(overlay == routeLine)
{
self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
self.routeLineView.fillColor = [UIColor colorWithRed:51 green:51 blue:255 alpha:1];
self.routeLineView.strokeColor = [UIColor colorWithRed:204 green:0 blue:0 alpha:1];
self.routeLineView.lineWidth = 3;
overlayView = routeLineView;
}
return overlayView;
}
所以我需要在地图上的点之间绘制的线条。该行的开头是第一个丢弃的引脚,最后是最后一个丢弃的引脚。
什么是routeLineView?这是什么样的UI元素? – 2013-02-04 02:11:32