Created
September 5, 2011 13:30
-
-
Save anonymous/1194994 to your computer and use it in GitHub Desktop.
Map Kit stuff
This file contains hidden or 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.Collections.Generic; | |
using System.Linq; | |
using MonoTouch.Foundation; | |
using MonoTouch.UIKit; | |
using LoadSiteList; | |
using MonoTouch.MapKit; | |
using MonoTouch.CoreLocation; | |
namespace MapsStuff | |
{ | |
public class Application | |
{ | |
static void Main (string[] args) | |
{ | |
UIApplication.Main (args); | |
} | |
} | |
// The name AppDelegate is referenced in the MainWindow.xib file. | |
public partial class AppDelegate : UIApplicationDelegate | |
{ | |
UITabBarController tabBarController; | |
os4MapsViewController viewController; | |
MapsStuff.TableViewController viewController2; | |
// This method is invoked when the application has loaded its UI and its ready to run | |
public override bool FinishedLaunching (UIApplication app, NSDictionary options) | |
{ | |
window = new UIWindow (UIScreen.MainScreen.Bounds); | |
tabBarController = new UITabBarController(); | |
viewController = new os4MapsViewController(); | |
viewController2 = new TableViewController(); | |
viewController.TabBarItem = new UITabBarItem ("Map", UIImage.FromFile("Images/103-map.png"), 0); | |
viewController2.TabBarItem = new UITabBarItem ("List", UIImage.FromFile("Images/103-map.png"), 0); | |
tabBarController.ViewControllers = new UIViewController[] {viewController, viewController2}; | |
window.AddSubview(tabBarController.View); | |
// If you have defined a view, add it here: | |
// window.AddSubview (navigationController.View); | |
window.MakeKeyAndVisible (); | |
return true; | |
} | |
// This method is required in iPhoneOS 3.0 | |
public override void OnActivated (UIApplication application) | |
{ | |
} | |
} | |
} |
This file contains hidden or 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 System.Collections.Generic; | |
using System.Diagnostics; | |
using MonoTouch.Foundation; | |
using MonoTouch.UIKit; | |
using MonoTouch.MapKit; | |
using MonoTouch.CoreLocation; | |
namespace MapsStuff | |
{ | |
public class os4MapsViewController: UIViewController | |
{ | |
private MKMapView _mapView { get; set; } | |
List<MapsStuff.MapAnnotation> pins; | |
public MKMapView MapView | |
{ | |
get { return _mapView; } | |
} | |
public os4MapsViewController () : base() | |
{} | |
public override void ViewDidLoad () | |
{ | |
base.ViewDidLoad (); | |
// | |
// Create our map view and add it as as subview. | |
// | |
pins = CreateRandomPins(); | |
_mapView = new MKMapView(); | |
_mapView.Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height); | |
_mapView.ShowsUserLocation = true; | |
_mapView.MapType = MKMapType.Hybrid; | |
_mapView.Delegate = new MapViewDelegate(); | |
foreach (MapAnnotation m in pins) | |
{ | |
_mapView.AddAnnotation(m); | |
} | |
View.AddSubview(_mapView); | |
} | |
List<MapsStuff.MapAnnotation> CreateRandomPins() | |
{ | |
Random r = new Random(); | |
List<MapsStuff.MapAnnotation> locations = new List<MapsStuff.MapAnnotation>(); | |
for (int i = 0; i < 4; i++) | |
{ | |
locations.Add( | |
new MapsStuff.MapAnnotation( | |
new CLLocationCoordinate2D(r.NextDouble() * 180, r.NextDouble() * 180), | |
"test" + i, | |
"sub" + i | |
)); | |
} | |
return locations; | |
} | |
} | |
public class MapViewDelegate : MKMapViewDelegate | |
{ | |
public MapViewDelegate (): base() | |
{ | |
} | |
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) | |
{ | |
var anv = mapView.DequeueReusableAnnotation("thislocation"); | |
if (anv == null) | |
{ | |
Console.WriteLine("creating new MKAnnotationView"); | |
anv = new MKPinAnnotationView(annotation, "thislocation"); | |
} | |
else | |
{ | |
anv.Annotation = annotation; | |
} | |
anv.Image = new UIImage("pin.png"); | |
anv.CanShowCallout = true; | |
return anv; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment