航空写真スライドショーを作る
今回のテーマはiOS Map SDKを使ったスライドショーアプリということで、お気に入りの場所の航空写真を順番にスライドショー表示する、というアプリを作ってみたいと思います。
表示する航空写真の場所は、数も縮尺も自由に決めていただいて問題ありませんが、Yahoo! JAPANが提供中のきれいな航空写真をぜひ見ていただきたいということで、サンプルとして、日本国内の山一覧(3,000m以上)でスライドショーを作成したいと思います。
その他にもドーム球場一覧、テレビ塔一覧、友達の出身地一覧など、アイデア次第で色々なスライドショーが作成できるので、ぜひお楽しみください。
以下は、今回作成するスライドショーアプリのソースコードの全容となります。
#import <UIKit/UIKit.h>
#import <YMapKit/YMapKit.h>
@interface YMapSlideShowAppDelegate : NSObject <UIApplicationDelegate,YMKMapViewDelegate> {
UIWindow *window;
YMKMapView *map; //YMKMapViewインスタンス用ポインタ
int counter; //スライドカウンター
UILabel* label; //テキストビュー
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
- (UITextView*)makeTextView:(CGRect)rect text:(NSString*)text;
@end
#import "YMapSlideShowAppDelegate.h"
#import <YMapKit/YMapKit.h>
@implementation YMapSlideShowAppDelegate
@synthesize window;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//YMKMapViewのインスタンスを作成
map = [[YMKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) appid:@" <あなたのアプリケーションID>" ];
//地図のタイプ 航空写真を設定
map.mapType = YMKMapTypeSatellite;
//YMKMapViewを追加
[window addSubview:map];
//YMKMapViewDelegateを登録
map.delegate = self;
//リソースファイルを読み込む
NSError* error;
NSString* path = [[NSBundle mainBundle] pathForResource:@" 3kmountains" ofType:@"xml"];
NSString* text = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
//YMKYDFManagerを作成
YMKYDFManager* ydfManager = [[YMKYDFManager alloc] initWithXmlString:text];
//航空写真にYDF情報を追加
[ydfManager showWithMapView:map];
//航空写真の位置と縮尺を設定
CLLocationCoordinate2D center;
center.latitude = 35.6657214;
center.longitude = 139.7310058;
map.region = YMKCoordinateRegionMake(center, YMKCoordinateSpanMake(0.05, 0.05));
//テキストビューの生成
UIFont* font=[UIFont systemFontOfSize:30];
CGRect rect=CGRectMake(10,30,320,120);
label=[[[UILabel alloc] init] autorelease];
[label setFrame:rect];
[label setText:@""];
[label setFont:font];
[label setTextColor:[UIColor whiteColor]];
[label setTextAlignment:UITextAlignmentLeft];
[label setBackgroundColor:[UIColor clearColor]];
[self.window addSubview:label];
[self.window makeKeyAndVisible];
//スライドショータイマー
counter = 0;
NSTimer* timer;
timer = [NSTimer scheduledTimerWithTimeInterval:5.0 // 発生間隔(秒)
target:self // 送信先オブジェクト
selector:@selector(onSlideShow:) // コールバック関数
userInfo:nil // パラメータ
repeats:NO]; // 繰り返し
return YES;
}
-(void)onSlideShow:(NSTimer*)timer
{
if( counter < [[map annotations] count] ){
//航空写真を移動
id <YMKAnnotation> annotation = [[map annotations] objectAtIndex:counter];
[label setText:[annotation title]];
YMKAnnotationView* annotationView = [map viewForAnnotation:annotation];
annotationView.hidden = YES;
[map setCenterCoordinate:annotation.coordinate animated:NO];
NSTimer* timer;
timer = [NSTimer scheduledTimerWithTimeInterval:5.0 // 発生間隔(秒)
target:self // 送信先オブジェクト
selector:@selector(onSlideShow:) // コールバック関数
userInfo:nil // パラメータ
repeats:NO]; // 繰り返し
counter++;
}
}
<あなたのアプリケーションID>の部分はご自分で取得されたアプリケーションIDに書き換えてください。
(C)Geoscience, NTT DATA, RESTEC /Included(C)JA
情報提供元: 財団法人 リモート・センシング技術センター
それでは、詳細を追っていきましょう。

