高德地图根据经纬度画折线, 虚线(以两个点为例)

- (void)createBrokenLine
{
   CLLocationCoordinate2D commonPolyLineCoords[2];
   for (int i =0; i < self.dataParkLaneArr.count; i ++) {
// 点的信息Model
       ParkInfo *parkInfo = self.dataParkLaneArr[i];
       // 点1  字符串形式的经纬度以逗号分隔;
       CGFloat p1Longitude = [parkInfo.entrance componentsSeparatedByString:@","][0].floatValue;
       CGFloat p1Latitude = [parkInfo.entrance componentsSeparatedByString:@","][1].floatValue;
       // 点2
       CGFloat p2Longitude = [parkInfo.exitus componentsSeparatedByString:@","][0].floatValue;
       CGFloat p2Latitude = [parkInfo.exitus componentsSeparatedByString:@","][1].floatValue;
        
        commonPolyLineCoords[0].longitude = p1Longitude;
        commonPolyLineCoords[0].latitude = p1Latitude;
        
        commonPolyLineCoords[1].longitude = p2Longitude;
        commonPolyLineCoords[1].latitude = p2Latitude;
    }

   MAPolyline *commonPoly = [MAPolylinepolylineWithCoordinates:commonPolyLineCoordscount:2];
    [self.mapViewaddOverlay:commonPoly];
}
//   MAMapViewDelegate
- (MAOverlayView *)mapView:(MAMapView *)mapView viewForOverlay:(id<MAOverlay>)overlay
{
    if ([overlayisKindOfClass:[MAPolylineclass]]) {
        MAPolylineView *lineView = [[MAPolylineViewalloc] initWithPolyline:overlay];
//    把实线变成虚线加下边的三行代码
        lineView.lineDashPhase =10; // 1
        NSArray* array = [NSArrayarrayWithObjects:[NSNumbernumberWithInt:15] , [NSNumbernumberWithInt:15],nil]; // 2
        lineView.lineDashPattern = array; // 3

        lineView.lineWidth =8.f;
        lineView.strokeColor = [UIColorcolorWithRed:0.318green:0.404blue:0.972alpha:1.000];
        lineView.lineJoin =kCGLineJoinMiter;
        lineView.lineCap =kCGLineCapButt;
        return lineView;
    }
    returnnil;
}


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页