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"];
}
}];