本文整理汇总了C#中MKMapView.RegionThatFits方法的典型用法代码示例。如果您正苦于以下问题:C# MKMapView.RegionThatFits方法的具体用法?C# MKMapView.RegionThatFits怎么用?C# MKMapView.RegionThatFits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MKMapView
的用法示例。
在下文中一共展示了MKMapView.RegionThatFits方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildView
//.........这里部分代码省略.........
if (CurrentDisplayMode == DisplayMode.Bikes)
{
valueToCheck = mapAnnotation.Bike.BikesAvailable;
} else {
valueToCheck = mapAnnotation.Bike.DocksAvailable;
}
if ((valueToCheck < 5 && valueToCheck != -1)) {
if (valueToCheck == 0)
{
pinView.PinColor = MKPinAnnotationColor.Red;
} else {
pinView.PinColor = MKPinAnnotationColor.Purple;
}
} else {
pinView.PinColor = MKPinAnnotationColor.Green;
}
mapAnnotation.PinView = pinView;
pinView.CanShowCallout = true;
return pinView;
}
if (annotation is CSRouteAnnotation)
{
var routeAnnotation = annotation as CSRouteAnnotation;
MKAnnotationView annotationView = null;
if (annotationView == null)
{
routeView = new CSRouteView(new RectangleF (0,0, mapView.Frame.Size.Width, mapView.Frame.Size.Height));
routeView.Annotation = routeAnnotation;
routeView.MapView = mapViewForAnnotation;
annotationView = routeView;
}
return annotationView;
}
return null;
};
List<MKAnnotation> locations = new List<MKAnnotation>();
double minLon = 200, minLat = 200, maxLon = -200, maxLat = -200;
foreach(var bike in BikeLocation.AllBikes)
{
if (bike.Location.Longitude < minLon) minLon = bike.Location.Longitude;
if (bike.Location.Latitude < minLat) minLat = bike.Location.Latitude;
if (bike.Location.Longitude < maxLon) maxLon = bike.Location.Longitude;
if (bike.Location.Latitude > maxLat) maxLat = bike.Location.Latitude;
locations.Add(new CycleAnnotation(bike));
}
if (locations.Count > 0)
{
mapView.AddAnnotation(locations.ToArray());
var tl = new CLLocationCoordinate2D(-90, 180);
var br = new CLLocationCoordinate2D(90, -180);
foreach(MKAnnotation an in mapView.Annotations)
{
tl.Longitude = Math.Min(tl.Longitude, an.Coordinate.Longitude);
tl.Latitude = Math.Max(tl.Latitude, an.Coordinate.Latitude);
br.Longitude = Math.Max(br.Longitude, an.Coordinate.Longitude);
br.Latitude = Math.Min(br.Latitude, an.Coordinate.Latitude);
}
var center = new CLLocationCoordinate2D {
Latitude = tl.Latitude - (tl.Latitude - br.Latitude) *0.5,
Longitude = tl.Longitude - (tl.Longitude - br.Longitude) *0.5
};
var span = new MKCoordinateSpan
{
LatitudeDelta = Math.Abs(tl.Latitude - br.Latitude) *0.5,
LongitudeDelta = Math.Abs(tl.Longitude - br.Longitude) *0.5
};
MKCoordinateRegion region = new MKCoordinateRegion (center, span );
region = mapView.RegionThatFits(region);
mapView.SetRegion(region, true);
}
mapView.ShowsUserLocation = true;
View.AddSubview(mapView);
}
}