Skip to content

Instantly share code, notes, and snippets.

@xbora
Created December 6, 2012 19:22
Show Gist options
  • Save xbora/4227467 to your computer and use it in GitHub Desktop.
Save xbora/4227467 to your computer and use it in GitHub Desktop.
Map View
class MapViewController < UIViewController
attr_accessor :selected_show
def didReceiveMemoryWarning
super
AH.alert("Memory issue", "Received memory warning.")
end
def viewDidLoad
self.customize_background
self.set_venue_map
end
def viewDidUnload
@venue_map_view.delegate = nil
@venue_map_view = nil
end
def viewDidAppear(animated)
super
end
def viewDidDisappear(animated)
super
end
def customize_background
self.view.backgroundColor = ThemeManager.instance.theme.white_background
end
def set_venue_map
@venue_map_view = MKMapView.alloc.initWithFrame(view.bounds)
@venue_map_view.mapType = MKMapTypeStandard
@venue_map_view.scrollEnabled = true
@venue_map_view.showsUserLocation = true
@venue_map_view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
@venue_map_view.delegate = self
@venue_map_view = self.set_map_region(self.venue_location)
view.addSubview(@venue_map_view)
@venue_map_view = self.set_venue_map_annotation
end
def set_venue_map_annotation
annotation = self.map_annotation
@venue_map_view.addAnnotation(annotation)
selector_array = []
selector_array << @venue_map_view
selector_array << annotation
self.performSelector("select_annotation:", withObject:selector_array, afterDelay:1.5)
end
def select_annotation(selector_array)
@venue_map_view = selector_array[0]
annotation = selector_array[1]
@venue_map_view.selectAnnotation(annotation, animated:true)
end
def set_map_region(location)
region = MKCoordinateRegionMake(location, MKCoordinateSpanMake(0.03, 0.03))
@venue_map_view.setRegion(region)
end
def map_annotation
venue_title = @selected_show["venue"]["name"]
venue_address = AH.show_address_city_state(@selected_show["venue"])
VenueAnnotation.alloc.initWithCoordinates(self.venue_location, title:venue_title, subTitle:venue_address)
end
def venue_location
CLLocationCoordinate2DMake(self.venue_lat, self.venue_lng)
end
def venue_lat
@selected_show["venue"]["location"].latitude
end
def venue_lng
@selected_show["venue"]["location"].longitude
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment