使用MKMapsnapshotter时出现错误图像。 我尝试手动缩小(设置更高的相机高度),这似乎解决了问题,但我不知道如何以编程方式处理此问题。有没有办法检测这种错误然后重置相机高度?这是一个MapKit错误吗?当我使用卫星或混合地图类型时会发生这种情况。
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
if (!snapshot.image || error) {
// Can't create snapshot. Use Placeholder
mapImage.image = [UIImage imageNamed:@"NoPhoto.png"];
NSLog(@"Snapshot Error: %@",[error localizedDescription]);
}
非常感谢任何帮助。谢谢!
编辑:
经过更多的研究和测试,我找到了解决方法。
此错误图像主要发生在海洋/海洋的卫星图像中。我发现我可以使用反向地理编码器并检查地标数组以查看该位置是否在城市中。如果没有,那么它可能是在海洋上。
// Check location of satellite imagery
CLLocation *location = [[CLLocation alloc] initWithLatitude:myLatitude longitude:myLongitude];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray* placemarks, NSError* error){
// check to see if location is in a city
if ([placemarks[0] locality]) {
// set up camera
MKMapCamera *myCamera = [MKMapCamera
cameraLookingAtCenterCoordinate:location.coordinate
fromEyeCoordinate:location.coordinate
eyeAltitude:250];
// set snapshot options
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
options.camera = myCamera;
options.showsBuildings = YES;
options.showsPointsOfInterest = NO;
options.mapType = MKMapTypeSatellite;
options.scale = [UIScreen mainScreen].scale;
options.size = myImage.frame.size;
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
if(!error) {
myImage.image = snapshot.image;
}
}]; // end snapshotter completion handler
} else {
// probably in the ocean
myImage.image = [UIImage imageNamed:@"NoPhoto.png"];
}
}];