add mapview sample

This commit is contained in:
Laurent Sansonetti
2011-10-11 22:26:00 +02:00
parent e279209642
commit 318dc185ca
2 changed files with 45 additions and 0 deletions

7
sample/mapview/Rakefile Normal file
View File

@@ -0,0 +1,7 @@
$:.unshift('../../lib')
require 'rubixir/rake'
Rubixir::CONFIG.app_name = 'mapview'
Rubixir::CONFIG.frameworks << 'CoreLocation'
Rubixir::CONFIG.frameworks << 'MapKit'
Rubixir::CONFIG.frameworks << 'AddressBook'

View File

@@ -0,0 +1,38 @@
class Beer
def initialize(lat, long, name)
@name = name
@coordinate = CLLocationCoordinate2D.new
@coordinate.latitude = lat
@coordinate.longitude = long
end
def title; @name; end
def coordinate; @coordinate; end
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
mvrect = window.bounds
mv = MKMapView.alloc.initWithFrame(mvrect)
mv.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth
# Center on Brussels.
region = MKCoordinateRegionMake(CLLocationCoordinate2D.new(50.85, 4.35), MKCoordinateSpanMake(3.1, 3.1))
mv.setRegion(region)
beers = [
Beer.new(50.016667, 4.316667, 'Chimay'),
Beer.new(49.639722, 5.348889, 'Orval'),
Beer.new(50.178162, 5.219879, 'Rochefort'),
Beer.new(51.284720, 4.656670, 'Westmalle'),
Beer.new(50.895942, 2.721262, 'Westvleteren'),
Beer.new(51.298800, 5.488570, 'Achel')
]
beers.each { |beer| mv.addAnnotation(beer) }
window.addSubview(mv)
window.makeKeyAndVisible
end
end