-
-
Save jackbillstrom/1ae20bca3057d90503c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Drawing; | |
using MonoTouch.Foundation; | |
using MonoTouch.UIKit; | |
using MonoTouch.MapKit; | |
using MonoTouch.CoreLocation; | |
using FlyoutNavigation; | |
using MonoTouch.Dialog; | |
namespace mvc_iphone | |
{ | |
public partial class DashboardScreen : UIViewController | |
{ | |
MKMapView mapView; | |
public DashboardScreen () : base ("DashboardScreen", null) | |
{ | |
this.Title = "Hem"; | |
} | |
public override void DidReceiveMemoryWarning () | |
{ | |
// Releases the view if it doesn't have a superview. | |
base.DidReceiveMemoryWarning (); | |
// Release any cached data, images, etc that aren't in use. | |
} | |
public override void ViewDidLoad () | |
{ | |
base.ViewDidLoad (); | |
// Hide "Back" button | |
this.NavigationItem.SetHidesBackButton (true, false); | |
mapView = new MKMapView (View.Bounds); | |
mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; | |
View.AddSubview (mapView); | |
mapView.MapType = MKMapType.Standard; | |
mapView.ShowsUserLocation = true; | |
var navigation = new FlyoutNavigationController { | |
// Create the navigation menu | |
NavigationRoot = new RootElement ("Navigation") { | |
new Section ("Navigering") { | |
new StringElement ("Profil"), | |
new StringElement ("Karta"), | |
new StringElement ("Inställningar"), | |
new StringElement ("Förarläge") | |
} | |
}, | |
// Supply view controllers corresponding to menu items: | |
ViewControllers = new [] { | |
new UIViewController { View = new UILabel { Text = "Vegetables (drag right)" } }, | |
new UIViewController { View = mapView }, | |
new UIViewController { View = new UILabel { Text = "Minerals (drag right)" } }, | |
new UIViewController { View = new UILabel { Text = "TJO" } } | |
}, | |
}; | |
// När användarens position uppdateras | |
mapView.DidUpdateUserLocation += (sender, e) => { | |
if (mapView.UserLocation != null) { | |
CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate; | |
MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coords.Latitude)); | |
mapView.Region = new MKCoordinateRegion(coords, span); | |
} | |
}; | |
this.NavigationItem.SetLeftBarButtonItem ( | |
new UIBarButtonItem (UIBarButtonSystemItem.Action, (sender, args) => { | |
// Show the navigation view | |
navigation.ToggleMenu (); | |
navigation.View.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; | |
View.AddSubview (navigation.View); | |
}), true); | |
} | |
public double MilesToLatitudeDegrees(double miles) | |
{ | |
double earthRadius = 3960.0; // in miles | |
double radiansToDegrees = 180.0/Math.PI; | |
return (miles/earthRadius) * radiansToDegrees; | |
} | |
public double MilesToLongitudeDegrees(double miles, double atLatitude) | |
{ | |
double earthRadius = 3960.0; // in miles | |
double degreesToRadians = Math.PI/180.0; | |
double radiansToDegrees = 180.0/Math.PI; | |
// derive the earth's radius at that point in latitude | |
double radiusAtLatitude = earthRadius * Math.Cos(atLatitude * degreesToRadians); | |
return (miles / radiusAtLatitude) * radiansToDegrees; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment