Created
December 19, 2011 18:02
-
-
Save timrisi/1498188 to your computer and use it in GitHub Desktop.
MapKitTest
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 MonoTouch.UIKit; | |
using System.Drawing; | |
using System; | |
using MonoTouch.Foundation; | |
using System.IO; | |
using MonoTouch.MapKit; | |
using MonoTouch.CoreLocation; | |
namespace MapKitTest | |
{ | |
public class MapView : UIViewController | |
{ | |
MKMapView map; | |
public MapView () : base () | |
{ | |
Initialize (); | |
} | |
public void Initialize() | |
{ | |
map = new MKMapView(); | |
map.Frame = new RectangleF(0, 0, 320, 460); | |
map.MapType = MKMapType.Hybrid; | |
map.GetViewForOverlay = GetViewForOverlay; | |
//map.RegionChanged += RegionChanged; | |
CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D(61.16806, -149.8725); | |
MKCoordinateRegion region = new MKCoordinateRegion(mapCenter, new MKCoordinateSpan(.16, .16)); | |
map.Region = region; | |
MKPolygon[,] polyArray = new MKPolygon[10, 50]; | |
for(int x = 0; x < 10; x++) | |
{ | |
for (int y = 0; y < 50; y++) | |
{ | |
CLLocationCoordinate2D[] points = new CLLocationCoordinate2D[4]; | |
points[0] = new CLLocationCoordinate2D(61.26806 - 0.02*x, -149.9725 + 0.004*y); | |
points[1] = new CLLocationCoordinate2D(61.26806 - 0.02*x, -149.9725 + 0.004*(y + 1)); | |
points[2] = new CLLocationCoordinate2D(61.26806 - 0.02*(x + 1), -149.9725 + 0.004*(y + 1)); | |
points[3] = new CLLocationCoordinate2D(61.26806 - 0.02*(x + 1), -149.9725 + 0.004*y); | |
polyArray[x, y] = MKPolygon.FromCoordinates(points); | |
} | |
} | |
View.AddSubview(map); | |
foreach(MKPolygon poly in polyArray) | |
map.AddOverlay(poly); | |
} | |
public override void ViewDidLoad () | |
{ | |
UIView view = new UIView(new System.Drawing.RectangleF(0, 20, 320, 420)); | |
view.BackgroundColor = UIColor.White; | |
View = view; | |
} | |
public MKOverlayView GetViewForOverlay (MKMapView mapView, NSObject overlay) | |
{ | |
//if (mapView.Region.Span.LatitudeDelta > .02 || mapView.Region.Span.LongitudeDelta > .028) | |
// return null; | |
if (overlay.GetType() == typeof(MKPolygon)) | |
{ | |
MKPolygonView aView = new MKPolygonView((MKPolygon)overlay); | |
aView.StrokeColor = UIColor.Gray; | |
aView.LineWidth = 2; | |
return aView; | |
} | |
return null; | |
} | |
public void RegionChanged(object sender, MKMapViewChangeEventArgs e) | |
{ | |
double latDelta = map.Region.Span.LatitudeDelta; | |
double lonDelta = map.Region.Span.LongitudeDelta; | |
double centerLat = map.Region.Center.Latitude; | |
double centerLon = map.Region.Center.Longitude; | |
UIAlertView alert = new UIAlertView("Span", | |
String.Format ("Latitude Delta: {0}\nLongitudeDelta: {1}", latDelta, lonDelta), | |
null, | |
"Okay", | |
null); | |
alert.Show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment