public void Overlays7() { if (!TestRuntime.CheckSystemAndSDKVersion(7, 0)) { Assert.Inconclusive("requires 7.0+"); } using (var polygon = new MKPolygon()) using (var polyline = new MKPolyline()) using (var circle = new MKCircle()) using (var tile = new MKTileOverlay()) using (MKMapView mv = new MKMapView()) { // new API accepted MKOverlay (better protocol support) mv.AddOverlay(polygon, MKOverlayLevel.AboveLabels); mv.AddOverlay(tile, MKOverlayLevel.AboveLabels); Assert.That(mv.Overlays.Length, Is.EqualTo(2), "1"); mv.RemoveOverlay(tile); mv.RemoveOverlay(polygon); Assert.That(mv.Overlays, Is.Empty, "2"); IMKOverlay[] list = { polygon, polyline, circle, tile }; mv.AddOverlays(list, MKOverlayLevel.AboveRoads); Assert.That(mv.Overlays.Length, Is.EqualTo(4), "3"); mv.RemoveOverlays(list); Assert.That(mv.Overlays, Is.Empty, "4"); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // add the map view var map = new MKMapView(UIScreen.MainScreen.Bounds); View.Add(map); // change the map style map.MapType = MKMapType.Standard; // enable/disable interactions // map.ZoomEnabled = false; // map.ScrollEnabled = false; // show user location if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { locationManager.RequestWhenInUseAuthorization(); } map.ShowsUserLocation = true; // specify a custom map delegate var mapDelegate = new MyMapDelegate(); map.Delegate = mapDelegate; // add a point annotation map.AddAnnotation(new MKPointAnnotation() { Title = "MyAnnotation", Coordinate = new CLLocationCoordinate2D(42.364260, -71.120824) }); // add a custom annotation // map.AddAnnotation(new CustomAnnotation("CustomSpot", new CLLocationCoordinate2D(38.364260, -68.120824))); // TODO: Step 4a - draw a circle overlay var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(33.755, -84.39), 100 * 1609.34); // 1609.34 = meters in a mile map.AddOverlay(circleOverlay); // TODO: Step 4b - draw a polygon (Wyoming) var stateOverlay = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[] { new CLLocationCoordinate2D(45.00, -111.00), new CLLocationCoordinate2D(45, -104), new CLLocationCoordinate2D(41, -104), new CLLocationCoordinate2D(41, -111) }); map.AddOverlay(stateOverlay); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (isLoaded) { nativeMap.RemoveOverlays(nativeMap.Overlays); } if (e.NewElement == null) { return; } if (e.OldElement != null) { nativeMap = Control as MKMapView; } element = Element as ExtendedMap; mapDelegate = new MapDelegate(); nativeMap = Control as MKMapView; nativeMap.Delegate = null; nativeMap.Delegate = mapDelegate; var formsMap = (ExtendedMap)e.NewElement; CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[element.RouteCoordinates.Count]; int index = 0; int idCounter = 1; string icon = ""; icon = element.ImageSource; foreach (var circle in element.Circles) { var annot = new CustomAnnotation(new CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), element.CustomPins.FirstOrDefault().Label, "", false, icon); annot.Id = idCounter++; nativeMap.AddAnnotation(annot); //pinCollection.Add(annot.Id, item); annotations.Add(annot); var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius); nativeMap.AddOverlay(circleOverlay); } foreach (var position in element.RouteCoordinates) { var annot = new CustomAnnotation(new CLLocationCoordinate2D(position.Latitude, position.Longitude), element.CustomPins.FirstOrDefault().Label, "", false, icon); annot.Id = idCounter++; nativeMap.AddAnnotation(annot); //pinCollection.Add(annot.Id, item); annotations.Add(annot); coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } var routeOverlay = MKPolyline.FromCoordinates(coords); nativeMap.AddOverlay(routeOverlay); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.OldElement != null) { var nativeMap = Control as MKMapView; nativeMap.GetViewForAnnotation = null; nativeMap.OverlayRenderer = null; nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView -= OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView -= OnDidDeselectAnnotationView; } if (e.NewElement != null) { formsMap = (LocationMap)e.NewElement; nativeMap = Control as MKMapView; var circle = formsMap.Circle; nativeMap.OverlayRenderer = GetOverlayRenderer; if (circle.Position.Latitude != 0.0) { _circle = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius); nativeMap.AddOverlay(_circle); } /* Listen for circle change events */ MessagingCenter.Subscribe <CustomCircle>(this, "CircleChanged", (obj) => { if (_circle == null) { _circle = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(obj.Position.Latitude, obj.Position.Longitude), obj.Radius); nativeMap.AddOverlay(_circle); } else { nativeMap.RemoveOverlay(_circle); _circle.Dispose(); _circle = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(obj.Position.Latitude, obj.Position.Longitude), obj.Radius); nativeMap.AddOverlay(_circle); } }); nativeMap.GetViewForAnnotation = GetViewForAnnotation; nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView += OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView += OnDidDeselectAnnotationView; } }
/// <summary> /// Adds a polyline path based on helicopter destination and current position /// </summary> /// <param name="heliPin"></param> private void addFlightPath(CustomPin heliPin) { CoreLocation.CLLocationCoordinate2D[] cLLocationCoordinate2Ds = new CoreLocation.CLLocationCoordinate2D[2]; cLLocationCoordinate2Ds[0] = new CoreLocation.CLLocationCoordinate2D(heliPin.Position.Latitude, heliPin.Position.Longitude); cLLocationCoordinate2Ds[1] = new CoreLocation.CLLocationCoordinate2D(heliPin.HelicopterDetails.destinationPosition.Latitude, heliPin.HelicopterDetails.destinationPosition.Longitude); var currentFlightPathOptions = MKPolyline.FromCoordinates(cLLocationCoordinate2Ds); nativeMap.AddOverlay(currentFlightPathOptions); highlightedFlightPath = new Tuple <CustomPin, MKPolyline>(heliPin, currentFlightPathOptions); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // add the map view var map = new MKMapView(UIScreen.MainScreen.Bounds); View.Add(map); // change the map style map.MapType = MKMapType.Standard; // enable/disable interactions // map.ZoomEnabled = false; // map.ScrollEnabled = false; // show user location if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) { locationManager.RequestWhenInUseAuthorization(); } map.ShowsUserLocation = true; // specify a custom map delegate var mapDelegate = new MyMapDelegate(); map.Delegate = mapDelegate; // add a point annotation map.AddAnnotation(new MKPointAnnotation() { Title = "MyAnnotation", Coordinate = new CLLocationCoordinate2D(42.364260, -71.120824) }); // add a custom annotation // map.AddAnnotation(new CustomAnnotation("CustomSpot", new CLLocationCoordinate2D(38.364260, -68.120824))); // TODO: Step 4a - draw a circle overlay var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(33.755, -84.39), 100 * 1609.34); // 1609.34 = meters in a mile map.AddOverlay(circleOverlay); // TODO: Step 4b - draw a polygon (Wyoming) var stateOverlay = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[] { new CLLocationCoordinate2D(45.00, -111.00), new CLLocationCoordinate2D(45, -104), new CLLocationCoordinate2D(41, -104), new CLLocationCoordinate2D(41, -111) }); map.AddOverlay(stateOverlay); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { var pointAnnotation = (PolylinePointAnnotation)annotation; var annotationView = new XIPinAnnotationView(mapView, annotation, "ximpav") { Draggable = pointAnnotation.Polyline?.CanWrite == true, AnimatesDrop = true, CanShowCallout = true, }; annotationView.DragLocationChanged += (o, e) => { var value = annotationView.Frame; if (!isDragging || mapView?.Overlays == null) { return; } if (editPolyline != null) { mapView.RemoveOverlay(editPolyline); } var newPoints = pointAnnotation.Polyline.Value.ToCoordinates(); newPoints [pointAnnotation.Index] = e.DragLocation; editPolyline = MKPolyline.FromCoordinates(newPoints); mapView.AddOverlay(editPolyline); }; return(annotationView); }
public void showDirection(CLLocationCoordinate2D userCoordinate, CLLocationCoordinate2D destinationCoordinate) { var req = new MKDirectionsRequest() { Source = new MKMapItem(new MKPlacemark(userCoordinate)), Destination = new MKMapItem(new MKPlacemark(destinationCoordinate)), TransportType = MKDirectionsTransportType.Automobile, RequestsAlternateRoutes = true }; var dir = new MKDirections(req); dir.CalculateDirections((response, error) => { if (error == null) { //Add each Polyline from route to map as overlay foreach (var route in response.Routes) { map.AddOverlay(route.Polyline); } } else { Console.WriteLine(error.LocalizedDescription); } }); }
void UpdateRoute() { map.OverlayRenderer = GetOverlayRenderer; routeOverlay = null; var coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count]; var index = 0; foreach (var position in formsMap.RouteCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } routeOverlay = MKPolyline.FromCoordinates(coords); if (map.Overlays != null && map.Overlays.Any()) { map.RemoveOverlays(map.Overlays); } map.AddOverlay(routeOverlay); SetNeedsDisplay(); SetNeedsLayout(); }
void GetRoute() { var fromPlace = new MKMapItem(new MKPlacemark(_userLocation)); var toPlace = new MKMapItem(new MKPlacemark(_destination)); var request = new MKDirectionsRequest { Source = fromPlace, Destination = toPlace, RequestsAlternateRoutes = false, TransportType = MKDirectionsTransportType.Any }; var directions = new MKDirections(request); directions.CalculateDirections((r, e) => { if (r == null || !r.Routes.Any()) { return; } var route = r.Routes[0]; _mapView.AddOverlay(route.Polyline); }); }
protected void OnMapTapped(UIGestureRecognizer sender) { CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map); if (annotationMode) { var annotation = new MKPointAnnotation(tappedLocationCoord, "User annotation", ""); annotations.Add(annotation); map.AddAnnotation(annotation); } else { var overlay = MKCircle.Circle(tappedLocationCoord, 1000); map.AddOverlay(overlay); } }
void ShowDirections(MKMapItem destination, MKMapView mapView) { var source = new MKMapItem(new MKPlacemark(ViewController.currentLocation, (MKPlacemarkAddress)null)); var request = new MKDirectionsRequest() { Destination = destination, Source = source, RequestsAlternateRoutes = false, }; var directions = new MKDirections(request); directions.CalculateDirections((MKDirectionsResponse response, NSError e) => { if (this.route != null) { mapView.RemoveOverlay(this.route); } if (response == null || response.Routes.Length == 0) { return; } //save the overlay so we can remove it next time we draw route = response.Routes[0].Polyline; mapView.AddOverlay(route, MKOverlayLevel.AboveRoads); }); }
public override void ViewDidLoad() { base.ViewDidLoad(); Map = new MKMapView(View.Bounds) { RotateEnabled = true, ScrollEnabled = true, ZoomEnabled = true, Delegate = new MapDelegate(), MapType = MKMapType.Standard }; View.AddSubview(Map); foreach (var location in SampleData.Locations) { Map.AddOverlay(MKPolygon.FromCoordinates(location.BoundaryData .Select(boundaryLocation => new CLLocationCoordinate2D(boundaryLocation.Latitude, boundaryLocation.Longitude)) .ToArray())); Map.AddAnnotation(new MKPointAnnotation { Title = location.Title, Coordinate = new CLLocationCoordinate2D(location.Latitude, location.Longitude) }); } Map.ShowAnnotations(Map.Annotations, true); }
private void UpdatePolyLine() { //var nativeMap = Control as MKMapView; if (polyline != null) { nativeMap.RemoveOverlay(polyline); polyline.Dispose(); } nativeMap.OverlayRenderer = GetOverlayRenderer; CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count]; int index = 0; foreach (var position in formsMap.RouteCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } var routeOverlay = MKPolyline.FromCoordinates(coords); nativeMap.AddOverlay(routeOverlay); polyline = routeOverlay; }
protected override void DrawSearchAreaPolygon(Geoposition[] polygonData) { var polygonNativeCoordinates = polygonData.Select(CoordinateConverter.ConvertToNative); _currentSearchPolygon = MKPolygon.FromCoordinates(polygonNativeCoordinates.ToArray()); _nativeMap.AddOverlay(_currentSearchPolygon); }
protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.OldElement == null) { mapView = Control as MKMapView; myMap = e.NewElement as MyMap; mapView.OverlayRenderer = (m, o) => { if (lineRenderer == null) { lineRenderer = new MKPolylineRenderer(o as MKPolyline); lineRenderer.StrokeColor = UIColor.Red; lineRenderer.FillColor = UIColor.Red; } return(lineRenderer); }; var point1 = new CLLocationCoordinate2D(37, -122); var point2 = new CLLocationCoordinate2D(37, -122.001); var point3 = new CLLocationCoordinate2D(37.001, -122.002); lineOverlay = MKPolyline.FromCoordinates(new CLLocationCoordinate2D[] { point1, point2, point3 }); mapView.AddOverlay(lineOverlay); } }
public override void ViewDidLoad() { base.ViewDidLoad(); Title = "Pyramids of Giza"; mapView = new MKMapView(View.Bounds); mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; View.AddSubview(mapView); var coords = new CLLocationCoordinate2D(29.976111, 31.132778); // pyramids of giza, egypt var span = new MKCoordinateSpan(MilesToLatitudeDegrees(.75), MilesToLongitudeDegrees(.75, coords.Latitude)); // set the coords and zoom on the map mapView.MapType = MKMapType.Satellite; mapView.Region = new MKCoordinateRegion(coords, span); mapView.OverlayRenderer = (m, o) => { if (circleRenderer == null) { circleRenderer = new MKCircleRenderer(o as MKCircle); circleRenderer.FillColor = UIColor.Purple; circleRenderer.Alpha = 0.5f; } return(circleRenderer); }; circleOverlay = MKCircle.Circle(coords, 400); mapView.AddOverlay(circleOverlay); #region Not related to this sample int typesWidth = 260, typesHeight = 30, distanceFromBottom = 60; mapTypes = new UISegmentedControl(new CGRect((View.Bounds.Width - typesWidth) / 2, View.Bounds.Height - distanceFromBottom, typesWidth, typesHeight)); mapTypes.BackgroundColor = UIColor.White; mapTypes.Layer.CornerRadius = 5; mapTypes.ClipsToBounds = true; mapTypes.InsertSegment("Road", 0, false); mapTypes.InsertSegment("Satellite", 1, false); mapTypes.InsertSegment("Hybrid", 2, false); mapTypes.SelectedSegment = 1; // Road is the default mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin; mapTypes.ValueChanged += (s, e) => { switch (mapTypes.SelectedSegment) { case 0: mapView.MapType = MKMapType.Standard; break; case 1: mapView.MapType = MKMapType.Satellite; break; case 2: mapView.MapType = MKMapType.Hybrid; break; } }; View.AddSubview(mapTypes); #endregion }
public void RefreshOrganCircleOnMap(object o) { Device.BeginInvokeOnMainThread(() => { organTimeLeft--; if (organTimeLeft <= 0) { return; } else { double mapRadius; double distanceTime = organTimeLeft * 70; if (distanceTime > 500000) { mapRadius = 500000; } else { mapRadius = distanceTime; } Position currentPosition = customPin.Position; map.Circle = new CustomCircle { Position = currentPosition, Radius = mapRadius }; var circleOverlay = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(map.Circle.Position.Latitude, map.Circle.Position.Longitude), map.Circle.Radius); if (nativeMap.Overlays == null || nativeMap.Overlays.Length == 0) { return; } else { nativeMap.RemoveOverlay(nativeMap.Overlays[0]); customMapRenderer.circleRenderer = null; nativeMap.OverlayRenderer = customMapRenderer.GetOverlayRenderer; nativeMap.AddOverlay(circleOverlay); } } }); }
public override void ViewDidLoad() { base.ViewDidLoad(); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { locationManager.RequestWhenInUseAuthorization(); } // change map type, show user location and allow zooming and panning map.MapType = MKMapType.Standard; map.ShowsUserLocation = true; map.ZoomEnabled = true; map.ScrollEnabled = true; // set map center and region double lat = 30.2652233534254; double lon = -97.73815460962083; CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D(lat, lon); MKCoordinateRegion mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 100, 100); map.CenterCoordinate = mapCenter; map.Region = mapRegion; // set the map delegate mapDelegate = new MapDelegate(); map.Delegate = mapDelegate; // add a custom annotation at the map center map.AddAnnotations(new ConferenceAnnotation("Evolve Conference", mapCenter)); // add an overlay of the hotel MKPolygon hotelOverlay = MKPolygon.FromCoordinates( new CLLocationCoordinate2D[] { new CLLocationCoordinate2D(30.2649977168594, -97.73863627705), new CLLocationCoordinate2D(30.2648461170005, -97.7381627734755), new CLLocationCoordinate2D(30.2648355402574, -97.7381750192576), new CLLocationCoordinate2D(30.2647791309417, -97.7379872505988), new CLLocationCoordinate2D(30.2654525150319, -97.7377341711021), new CLLocationCoordinate2D(30.2654807195004, -97.7377994819399), new CLLocationCoordinate2D(30.2655089239607, -97.7377994819399), new CLLocationCoordinate2D(30.2656428950368, -97.738346460207), new CLLocationCoordinate2D(30.2650364981811, -97.7385709662122), new CLLocationCoordinate2D(30.2650470749025, -97.7386199493406) }); map.AddOverlay(hotelOverlay); UITapGestureRecognizer tap = new UITapGestureRecognizer(g => { var pt = g.LocationInView(map); CLLocationCoordinate2D tapCoord = map.ConvertPoint(pt, map); Console.WriteLine("new CLLocationCoordinate2D({0}, {1}),", tapCoord.Latitude, tapCoord.Longitude); }); map.AddGestureRecognizer(tap); }
protected override void DrawRouteInMap(IEnumerable <Geoposition> positions) { var nativeCoordinates = positions.Select(p => CoordinateConverter.ConvertToNative(p)); _currentUserRoute = MKPolyline.FromCoordinates(nativeCoordinates.ToArray()); _nativeMap.AddOverlay(_currentUserRoute); }
public void OnChange(object o, PropertyChangedEventArgs ar) { Device.BeginInvokeOnMainThread(() => { var pos = mapWithRoute.CurrentPosition; var cords = new CLLocationCoordinate2D(pos.Lat, pos.Lon); circleOverlay = MKCircle.Circle(cords, 20); nativeMap.AddOverlay(circleOverlay); }); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (isLoaded) { nativeMap.RemoveOverlays(nativeMap.Overlays); } if (e.OldElement != null) { nativeMap = Control as MKMapView; nativeMap.OverlayRenderer = null; } if (e.NewElement != null) { var formsMap = (CustomMap)e.NewElement; nativeMap = Control as MKMapView; isCircle = formsMap.DrawCircle; if (!isCircle) { nativeMap.OverlayRenderer = GetOverlayRenderer; CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count]; int index = 0; foreach (var position in formsMap.RouteCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } var routeOverlay = MKPolyline.FromCoordinates(coords); nativeMap.AddOverlay(routeOverlay); } if (isCircle) { var circle = formsMap.Circle; nativeMap.OverlayRenderer = GetOverlayRenderer; var circleOverlay = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius); nativeMap.AddOverlay(circleOverlay); } } }
public void updatePolygon() { var points = itemsArray.Select(l => l.Coordinate).ToArray(); if (Polygon != null) { mainMapView.RemoveOverlay(Polygon); } Polygon = MKPolygon.FromCoordinates(points); mainMapView.AddOverlay(Polygon); }
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if ((e.PropertyName.Equals("DrawPoint")) && formsMap.LocFlag == CommonMap.LocationFlag.Start && formsMap.DrawPoint != null && lastCoordinates.Count >= positionCount) { var polylineOptions = CreatePolylineOpty(lastCoordinates); lastCoordinates.RemoveRange(0, positionCount - 1); nativeMap.AddOverlay(polylineOptions); } if ((e.PropertyName.Equals("LastPFlag")) && formsMap.LocFlag == CommonMap.LocationFlag.Stop && formsMap.LastPFlag != null) { if (lastCoordinates.Count > 1) { var polylineOptions = CreatePolylineOpty(lastCoordinates); lastCoordinates.RemoveRange(0, lastCoordinates.Count - 1); nativeMap.AddOverlay(polylineOptions); } } if ((e.PropertyName.Equals("LastPFlag")) && formsMap.LocFlag == CommonMap.LocationFlag.Stop && formsMap.LastPFlag == null) { nativeMap.RemoveOverlays(nativeMap.Overlays); formsMap.platformRoad = new List <CLLocationCoordinate2D>(); wholeRoad = (List <CLLocationCoordinate2D>)formsMap.platformRoad; } if (e.PropertyName.Equals("DrawPoint") && formsMap.LocFlag == CommonMap.LocationFlag.Start && routeCoordinates != null && routeCoordinates.Count > 1 && (routeCoordinates.Count % refreshRoud) == 0) { RoudCreateOptimization(); } }
void FindZombieInfestedZones() { var circleOverlay = MKCircle.Circle(CDC.Coordinates, radius); map.AddOverlay(circleOverlay); map.OverlayRenderer = (mapView, overlay) => { if (overlay is MKCircle) { circleRenderer = new MKCircleRenderer(overlay as MKCircle) { FillColor = UIColor.Red, Alpha = 0.5f }; return(circleRenderer); } return(null); }; Helpers.CenterOnAtlanta(map); }
protected override void DrawCalculatedRouteInMap(RouteModel route) { var drawingManager = new MapDrawingManager(FormsMap, route.Color); _nativeMap.OverlayRenderer = drawingManager.GetOverlayRenderer; var nativeCoordinates = route.RoutePoints.Select(p => CoordinateConverter.ConvertToNative(p)); _currentUserRoute = MKPolyline.FromCoordinates(nativeCoordinates.ToArray()); _nativeMap.AddOverlay(_currentUserRoute); }
public override void ViewDidLoad() { base.ViewDidLoad (); Title = "Pyramids of Giza"; mapView = new MKMapView(View.Bounds); mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; View.AddSubview(mapView); var coords = new CLLocationCoordinate2D(29.976111, 31.132778); // pyramids of giza, egypt var span = new MKCoordinateSpan(MilesToLatitudeDegrees(.75), MilesToLongitudeDegrees(.75, coords.Latitude)); // set the coords and zoom on the map mapView.MapType = MKMapType.Satellite; mapView.Region = new MKCoordinateRegion(coords, span); mapView.OverlayRenderer = (m, o) => { if(circleRenderer == null) { circleRenderer = new MKCircleRenderer(o as MKCircle); circleRenderer.FillColor = UIColor.Purple; circleRenderer.Alpha = 0.5f; } return circleRenderer; }; circleOverlay = MKCircle.Circle (coords, 200); mapView.AddOverlay (circleOverlay); #region Not related to this sample int typesWidth=260, typesHeight=30, distanceFromBottom=60; mapTypes = new UISegmentedControl(new CGRect((View.Bounds.Width-typesWidth)/2, View.Bounds.Height-distanceFromBottom, typesWidth, typesHeight)); mapTypes.InsertSegment("Road", 0, false); mapTypes.InsertSegment("Satellite", 1, false); mapTypes.InsertSegment("Hybrid", 2, false); mapTypes.SelectedSegment = 1; // Road is the default mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin; mapTypes.ValueChanged += (s, e) => { switch(mapTypes.SelectedSegment) { case 0: mapView.MapType = MKMapType.Standard; break; case 1: mapView.MapType = MKMapType.Satellite; break; case 2: mapView.MapType = MKMapType.Hybrid; break; } }; View.AddSubview(mapTypes); #endregion }
private void Do_Rute(MKDirectionsRequest req, UIColor color, CLLocationCoordinate2D[] coord, MKMapView mapView) { var dir = new MKDirections(req); dir.CalculateDirections((response, error) => { if (error == null) { var rute = response.Routes[0]; var rteL = new MKPolylineRenderer(rute.Polyline) { LineWidth = 5.0f, StrokeColor = color }; mapView.OverlayRenderer = (mv, ol) => rteL; var circleoverlay = MKCircle.Circle(mapView.CenterCoordinate, 1000); mapView.AddOverlay(circleoverlay); int index = 0; foreach (var position in coord) { coord[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } var routeOverlay = MKPolyline.FromCoordinates(coord); mapView.AddOverlay(routeOverlay); mapView.SetCenterCoordinate(coord[1], true); //mapView.AddOverlay(rute.Polyline, MKOverlayLevel.AboveRoads); } else { Console.WriteLine("Error"); } }); }
CustomPin GetCustomPin(MKPointAnnotation annotation) { try { CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[((CustomMap)Element).RouteCoordinates.Count]; int index = 0; foreach (var position in ((CustomMap)Element).RouteCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } routeOverlay = MKPolyline.FromCoordinates(coords); nativeMap.AddOverlay(routeOverlay); if (annotation == null) { foreach (var pin in ((CustomMap)Element).CustomPins) { var position = new Position(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude); if (pin.Pin.Position == position) { return(pin); } } return(null); } else { var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude); foreach (var pin in ((CustomMap)Element).CustomPins) { if (pin.Pin.Position == position) { return(pin); } } return(null); } } catch (Exception ex) { return(null); } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.NewElement != null) { var map = new MKMapView(); //var ol = new MapOverlays.DistantTilesOverlayRender(Host); var ol = new MapOverlays.LocalTilesOverlayRender(); map.AddOverlay(ol, MKOverlayLevel.AboveLabels); map.OverlayRenderer = (mv, o) => new MKTileOverlayRenderer((MKTileOverlay)o); this.SetNativeControl(map); } }
public void Overlays7() { TestRuntime.AssertXcodeVersion(5, 0, 1); using (var polygon = new MKPolygon()) using (var polyline = new MKPolyline()) using (var circle = new MKCircle()) using (var tile = new MKTileOverlay()) using (MKMapView mv = new MKMapView()) { // new API accepted MKOverlay (better protocol support) mv.AddOverlay(polygon, MKOverlayLevel.AboveLabels); mv.AddOverlay(tile, MKOverlayLevel.AboveLabels); Assert.That(mv.Overlays.Length, Is.EqualTo(2), "1"); mv.RemoveOverlay(tile); mv.RemoveOverlay(polygon); Assert.That(mv.Overlays, Is.Empty, "2"); IMKOverlay[] list = { polygon, polyline, circle, tile }; mv.AddOverlays(list, MKOverlayLevel.AboveRoads); Assert.That(mv.Overlays.Length, Is.EqualTo(4), "3"); mv.RemoveOverlays(list); Assert.That(mv.Overlays, Is.Empty, "4"); } }
private void DrawRegionBorderPolyGon(MKMapView nativeMap) { nativeMap.OverlayRenderer = GetBorderOverlayRenderer; var coords = new CLLocationCoordinate2D[FormsMap.AvailableRegions.Count]; int index = 0; foreach (var borders in FormsMap.AvailableRegions) { coords[index] = new CLLocationCoordinate2D(borders.Latitude, borders.Longitude); index++; } var borderOverlay = MKPolygon.FromCoordinates(coords); nativeMap.AddOverlay(borderOverlay); }
public override void ViewDidLoad() { base.ViewDidLoad (); // // Create our map view and add it as as subview. // _mapView = new MKMapView(); _mapView.Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height); View.AddSubview(_mapView); _mapView.Delegate = new MapViewDelegate(this); LoadRoute(); if (RouteLine != null) { _mapView.AddOverlay(RouteLine); } ZoomInOnRoute(); }