Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void zoomToFitMapAnnotations()
- {
- if (map.Annotations.Length <= 0)
- return;
- var topLeftCoord = new CLLocationCoordinate2D(-90, 180);
- var bottomRightCoord = new CLLocationCoordinate2D(90, -180);
- foreach (var marker in map.Annotations)
- {
- topLeftCoord.Longitude = Math.Min(topLeftCoord.Longitude, marker.Coordinate.Longitude);
- topLeftCoord.Latitude = Math.Max(topLeftCoord.Latitude, marker.Coordinate.Latitude);
- bottomRightCoord.Longitude = Math.Max(bottomRightCoord.Longitude, marker.Coordinate.Longitude);
- bottomRightCoord.Latitude = Math.Min(bottomRightCoord.Latitude, marker.Coordinate.Latitude);
- }
- double delta = 1.4;
- MKCoordinateRegion region = new MKCoordinateRegion();
- region.Center.Latitude = topLeftCoord.Latitude - (topLeftCoord.Latitude - bottomRightCoord.Latitude)*0.5; //0.5
- region.Center.Longitude = topLeftCoord.Longitude + (bottomRightCoord.Longitude - topLeftCoord.Longitude)*0.5; //0.5
- region.Span.LatitudeDelta = Math.Abs((topLeftCoord.Latitude - bottomRightCoord.Latitude)* delta);
- region.Span.LongitudeDelta = Math.Abs((bottomRightCoord.Longitude - topLeftCoord.Longitude) * delta);
- region = map.RegionThatFits(region);
- map.SetRegion(region, true);
- }
- private void CenterMap(CLLocationCoordinate2D mapCenter)
- {
- InvokeOnMainThread(() =>
- {
- map.SetRegion(MKCoordinateRegion.FromDistance(mapCenter, 1000, 1000), true);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement