获取地图截图

主要的思路是调取高德地图的方法获取截图

前提是必须要加载地图,才能截图

1.加载截图

mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0,64, YBScreenBoundsWidth, 250)];

mapView.showsUserLocation=YES;

//这是个app进入的时候定位获取的位置信息

CLLocationDegrees  lat=[[[NSUserDefaults standardUserDefaults]valueForKey:@"lat"] doubleValue];

CLLocationDegrees longi=[[[NSUserDefaults standardUserDefaults]valueForKey:@"long"] doubleValue];

CLLocationCoordinate2D cllocation=CLLocationCoordinate2DMake(lat, longi);

mapView.centerCoordinate=cllocation;

mapView.zoomLevel=13;

///把地图添加至view

[self.view addSubview:mapView];

2.获取截图并上传

__block UIImage *screenshotImage = nil;

__block NSInteger resState = 0;

__block typeof(UIImage*) weekSnap = SnapshotImage;

[mapView takeSnapshotInRect:CGRectMake(0,64, YBScreenBoundsWidth, 250) withCompletionBlock:^(UIImage *resultImage, CGRect rect) {

SnapshotImage=resultImage;

CDLog(@"截图成功");

NSMutableArray *mdataArr=[[NSMutableArray alloc]initWithCapacity:0];

NSData *imageData = UIImageJPEGRepresentation(SnapshotImage, 0.5);

NSString *url=[[HJInterfaceManager sharedInstance]addRichInfo];

NSMutableDictionary *mdic=[[NSMutableDictionary alloc]initWithCapacity:0];

SelfDataModel *selfModel=[SelfDataModel returnModelBySelectFMDB];

//        * @param familyId

//        * @param userId

//        * @param content

//        * @param richContent

//        * @param type

//        * @param sendTime

NSDate *date=[NSDate date];

NSDateFormatter *form=[[NSDateFormatter alloc]init];

[form setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

NSString *datestr=[form stringFromDate:date ];

if (!self.isMyself) {

[mdic setObject:self.family.idNum forKey:@"familyId"];

}

[mdic setObject:selfModel.idNum forKey:@"userId"];

[mdic setObject:@"" forKey:@"content"];

[mdic setObject:[NSString stringWithFormat:@"%lf,%lf",

[[[NSUserDefaults standardUserDefaults]valueForKey:@"lat"] doubleValue],[[[NSUserDefaults standardUserDefaults]valueForKey:@"long"] doubleValue]] forKey:@"location"];

[mdic setObject:[imageData base64Encoding] forKey:@"richContents"];

[mdic setObject:self.type forKey:@"type"];

[mdic setObject:datestr forKey:@"sendTime"];

[HJHttpManager PostRequestWithUrl:url param:mdic finish:^(NSData *data) {

NSDictionary *dic=(NSDictionary *)data;

if ([dic[@"status"] isEqualToString:@"S"]) {

[MBProgressHUD hideHUD];

[MBProgressHUD showSuccess:@"发送成功"];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[self.navigationController popViewControllerAnimated:YES];

});

}else{

[MBProgressHUD hideHUD];

[MBProgressHUD showError:dic[@"message"]];

}

} failed:^(NSError *error) {

[MBProgressHUD hideHUD];

[MBProgressHUD showError:@"请求失败"];

NSLog(@"请求失败");

}];

}];

你可能感兴趣的:(获取地图截图)