Skip to content

Instantly share code, notes, and snippets.

@amay077
Created April 27, 2016 17:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amay077/793b5df4aad0098ffe6d9c12a491ee9a to your computer and use it in GitHub Desktop.
Save amay077/793b5df4aad0098ffe6d9c12a491ee9a to your computer and use it in GitHub Desktop.
Xamarin Workbooks を使ってみるテスト。 ``HowToUseMapKit.workbook`` で保存して Xamarin Inspector で File->Open してね。
{"exec-mode":"default","platform":"iOS","uti":"com.xamarin.workbook","packages":[]}

Xamarin Workbooks を使って iOS アプリに地図を表示させてみよう

これは Xamarin Workbooks を使ってみるテストです。

この .workbook ファイルを、 Xamarin Inspector で File -> Open して再生すると iOS シミュレータで地図(MapKit)が表示できるはず。(あ、Mac でね)

名前空間の定義

using UIKit;
using MapKit;
using CoreLocation;

Window と ViewController の準備

ここらへんは Storyboard を使えばやる必要ないんで参考程度に

var window = new UIWindow(UIScreen.MainScreen.Bounds);
window.MakeKeyAndVisible();
var controller = new UIViewController();
window.RootViewController = controller;

地図を生成して ViewController に追加

同じく Storyboard を使えばやる必要ないんで参考程度に

var mapView = new MKMapView(UIScreen.MainScreen.Bounds);
controller.View = mapView;

地図の設定とか

東京駅周辺にズーンとズームイン!

var region = new MKCoordinateRegion();
region.Center = new CLLocationCoordinate2D(35.68d, 139.76d); // 東京駅
region.Span.LatitudeDelta = 0.01d;  // 割とズームイン
region.Span.LongitudeDelta = 0.01d;
mapView.SetRegion(region, true);

なんかすげえぞ

.workbook ファイルの実体は、ヘッダに json が入ってるけど Markdown。 なので、 Markdown のプレビューツールで普通にいい感じに表示できる。 それでいて実行可能!しかもインタラクティブ! これは 世界が変わる予感

おわり

@amay077
Copy link
Author

amay077 commented Apr 28, 2016

xamarin_workbooks_02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment