public void CenterOnLocations(List <LatitudeLongitude> locations , bool with_animation = false) { if (locations == null || locations.Count == 0) { return; } var minLat = locations.Select(el => el.Latitude).Min(); var minLong = locations.Select(el => el.Longitude).Min(); var maxLat = locations.Select(el => el.Latitude).Max(); var maxLong = locations.Select(el => el.Longitude).Max(); var coordinateMin = new CLLocationCoordinate2D(minLat, minLong); var coordinateMax = new CLLocationCoordinate2D(maxLat, maxLong); var upperLeft = MKMapPoint.FromCoordinate(coordinateMin); var lowerRight = MKMapPoint.FromCoordinate(coordinateMax); var mapRect = new MKMapRect(upperLeft.X , upperLeft.Y , lowerRight.X - upperLeft.X , lowerRight.Y - upperLeft.Y); var region = MKCoordinateRegion.FromMapRect(mapRect); MapViewControl.SetVisibleMapRect(mapRect , new UIEdgeInsets(50, 20, 100, 20) , true); try { if (region.Center.Latitude > -89 && region.Center.Latitude < 89 && region.Center.Longitude > -179 && region.Center.Longitude < 179) { if (region.Span.LatitudeDelta < 0) { region.Span.LatitudeDelta = 0.0; } if (region.Span.LongitudeDelta < 0) { region.Span.LongitudeDelta = 0.0; } MapViewControl.SetRegion(region, with_animation); } } catch (Exception) { //UIAlertView alert = new UIAlertView("Exception", String.Format("{0} \n {1}?", e.Message, e.StackTrace), null, "Cancel"); //alert.Show(); } }
private void ZoomInButton_TouchUpInside(object sender, EventArgs e) { _zoomInButton.UserInteractionEnabled = false; var region = MapViewControl.Region; var span = MapViewControl.Region.Span; region.Center = MapViewControl.Region.Center; span.LatitudeDelta = MapViewControl.Region.Span.LatitudeDelta / 2.0002; span.LongitudeDelta = MapViewControl.Region.Span.LongitudeDelta / 2.0002; region.Span = span; MapViewControl.SetRegion(region, true); _zoomInButton.UserInteractionEnabled = true; }
public void CenterInLocalisation(double latitude , double longitude , float zoomLevel , bool withAnimation = false) { var mapCenter = new CLLocationCoordinate2D(latitude, longitude); if (zoomLevel != 0) { var span = new MKCoordinateSpan(0, 360 / Math.Pow(2, zoomLevel) * MapViewControl.Frame.Size.Width / 256); var mapRegion = new MKCoordinateRegion(mapCenter, span); MapViewControl.CenterCoordinate = mapCenter; MapViewControl.SetRegion(mapRegion, withAnimation); } else { MapViewControl.CenterCoordinate = mapCenter; } }
private void ZoomOutButton_TouchUpInside(object sender, EventArgs e) { _zoomOutButton.UserInteractionEnabled = false; var region = MapViewControl.Region; var span = MapViewControl.Region.Span; region.Center = MapViewControl.Region.Center; span.LatitudeDelta = MapViewControl.Region.Span.LatitudeDelta * 2; span.LongitudeDelta = MapViewControl.Region.Span.LongitudeDelta * 2; region.Span = span; if (span.LatitudeDelta > 200 || span.LongitudeDelta > 200) { return; } MapViewControl.SetRegion(region, true); _zoomOutButton.UserInteractionEnabled = true; }
private void SelectAnnotation() { MapViewControl.RemoveAnnotations(MapViewControl.Annotations); if (ViewModel.Annotation != null && ViewModel.Annotation.Addresses != null && ViewModel.Annotation.Addresses.Length > 0) { var annotations = ViewModel.Annotation.Addresses .Select(address => new MapViewAnnotation( ViewModel.Annotation.Pin, ViewModel.Annotation.Title, address)).ToArray(); var coordinates = MapUtil.GetAnnotationsCoordinates(annotations); MapViewControl.SetRegion( MapUtil.CoordinateRegionForCoordinates( coordinates, new MKMapSize(5000, 5000)), false); MapViewControl.AddAnnotations(annotations); MapViewControl.SelectAnnotation(annotations[0], false); } }