public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // Create a MapView mapView = new MGLMapView(View.Bounds); mapView.StyleURL = MGLStyle.LightStyleURLWithVersion(9); mapView.TintColor = UIColor.DarkGray; mapView.SetZoomLevel(1, false); mapView.WeakDelegate = this; View.AddSubview(mapView); // Polyline // Create a coordinates array with all of the coordinates for our polyline. List <CLLocationCoordinate2D> coordinates = new List <CLLocationCoordinate2D>() { new CLLocationCoordinate2D(35, -25), new CLLocationCoordinate2D(20, -30), new CLLocationCoordinate2D(0, -25), new CLLocationCoordinate2D(-15, 0), new CLLocationCoordinate2D(-45, 10), new CLLocationCoordinate2D(-45, 40) }; var coords = coordinates.ToArray(); //TODO Use CustomPolyline MGLPolyline polyline = CustomPolyline.PolylineWithCoordinates(ref coords[0], (uint)coords.Count()); // Set the custom `color` property, later used in the `mapView:strokeColorForShapeAnnotation:` delegate method. //((CustomPolyline)polyline).Color = UIColor.DarkGray; // Add the polyline to the map. Note that this method name is singular. mapView.AddAnnotation(polyline); // Point Annotations // Add a custom point annotation for every coordinate (vertex) in the polyline. List <CustomPointAnnotation> pointAnnotations = new List <CustomPointAnnotation>(); foreach (var coordinate in coordinates) { CustomPointAnnotation point = new CustomPointAnnotation(coordinate, "Custom Point Annotation " + pointAnnotations.Count + 1, ""); pointAnnotations.Add(point); } mapView.AddAnnotations(pointAnnotations.ToArray()); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. mapView = new MGLMapView(View.Bounds, MGLStyle.LightStyleURLWithVersion(9)); // Set the map’s center coordinate and zoom level. mapView.SetCenterCoordinate(new CLLocationCoordinate2D(36.54, -116.97), 9, false); // Set the delegate property of our map view to `self` after instantiating it. mapView.WeakDelegate = this; View.AddSubview(mapView); MyCustomPointAnnotation pointA = new MyCustomPointAnnotation(); pointA.Coordinate = new CLLocationCoordinate2D(36.4623, -116.8656); pointA.Title = "Stovepipe Wells"; pointA.WillUseImage = true; MyCustomPointAnnotation pointB = new MyCustomPointAnnotation(); pointB.Coordinate = new CLLocationCoordinate2D(36.6071, -117.1458); pointB.Title = "Furnace Creek"; pointB.WillUseImage = true; MyCustomPointAnnotation pointC = new MyCustomPointAnnotation(); pointC.Coordinate = new CLLocationCoordinate2D(36.4208, -116.8101); pointC.Title = "Zabriskie Point"; MyCustomPointAnnotation pointD = new MyCustomPointAnnotation(); pointD.Coordinate = new CLLocationCoordinate2D(36.6836, longitude: -117.1005); pointD.Title = "Mesquite Flat Sand Dunes"; MyCustomPointAnnotation[] myPlaces = new MyCustomPointAnnotation[4] { pointA, pointB, pointC, pointD }; mapView.AddAnnotations(myPlaces);; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. mapView = new MGLMapView(View.Bounds); // Set the map’s center coordinate and zoom level mapView.SetCenterCoordinate(new CLLocationCoordinate2D(0, 66), false); mapView.SetZoomLevel(2, false); mapView.StyleURL = MGLStyle.DarkStyleURLWithVersion(9); // Set the delegate property of our map view to `self` after instantiating it mapView.WeakDelegate = this; View.AddSubview(mapView); // Specify coordinates for our annotations. List <CLLocationCoordinate2D> coordinates = new List <CLLocationCoordinate2D>(); coordinates.Add(new CLLocationCoordinate2D(0, 33)); coordinates.Add(new CLLocationCoordinate2D(0, 66)); coordinates.Add(new CLLocationCoordinate2D(0, 99)); List <MGLPointAnnotation> pointAnnotations = new List <MGLPointAnnotation>(); // Fill an array with point annotations and add it to the map. foreach (var coord in coordinates) { MGLPointAnnotation point = new MGLPointAnnotation(); point.Coordinate = coord; point.Title = $"Lat: {coord.Latitude}, Long: {coord.Longitude}"; pointAnnotations.Add(point); } mapView.AddAnnotations(pointAnnotations.ToArray()); }