void SetMapToCoordinate(CoreLocation.CLLocationCoordinate2D coordinate) { var currentSpan = new MapKit.MKCoordinateSpan(0.05, 0.05); var region = new MapKit.MKCoordinateRegion(coordinate, currentSpan); MyMap.SetRegion(region, true); }
void SetMapToCoordinate(CoreLocation.CLLocationCoordinate2D coordinate) { var currentSpan = new MapKit.MKCoordinateSpan (0.05, 0.05); var region = new MapKit.MKCoordinateRegion (coordinate, currentSpan); MyMap.SetRegion (region, true); }
private void OriginMapView_DidUpdateUserLocation(object sender, MapKit.MKUserLocationEventArgs e) { // throw new NotImplementedException(); // Check whether location set to something if (originMapView.UserLocation != null) { var coordinates = originMapView.UserLocation.Coordinate; // get center var span = new MapKit.MKCoordinateSpan(0.15, 0.15); // how many degrees of lat/lng to show inside the span originMapView.Region = new MapKit.MKCoordinateRegion(coordinates, span); originMapView.RemoveAnnotations(); // clear all annotations from previous operations from location/map updates originMapView.AddAnnotation(new MKPointAnnotation() { Coordinate = coordinates, Title = "My own location" }); } }
// MKCoordinateRegionMake public MKCoordinateRegion(CLLocationCoordinate2D center, MKCoordinateSpan span) { this.Center = center; this.Span = span; }
public static void ChangeRegionSpanDependingOnPinchScale(this MKMapView mapView, MKCoordinateSpan originalSpan, nfloat scale) { var centerPixelX = LongitudeToPixelSpaceX(mapView.Region.Center.Longitude); var centerPixelY = LatitudeToPixelSpaceY(mapView.Region.Center.Latitude); var topLeftLongitude = mapView.Region.Center.Longitude - (originalSpan.LongitudeDelta / 2); var topLeftLatitude = mapView.Region.Center.Latitude - (originalSpan.LatitudeDelta / 2); var topLeftPixelX = LongitudeToPixelSpaceX(topLeftLongitude); var topLeftPixelY = LatitudeToPixelSpaceY(topLeftLatitude); var deltaPixelX = Math.Abs(centerPixelX - topLeftPixelX); var deltaPixelY = Math.Abs(centerPixelY - topLeftPixelY); var scaledDeltaPixelX = deltaPixelX / scale; var scaledDeltaPixelY = deltaPixelY / scale; var newLongitudeForTopLeft = PixelSpaceXToLongitude(centerPixelX - scaledDeltaPixelX); var newLatitudeForTopLeft = PixelSpaceYToLatitude(centerPixelY - scaledDeltaPixelY); var newDeltaLongitude = Math.Abs(newLongitudeForTopLeft - mapView.Region.Center.Longitude) * 2; var newDeltaLatitude = Math.Abs(newLatitudeForTopLeft - mapView.Region.Center.Latitude) * 2; newDeltaLatitude = Math.Max(0.0f, Math.Min(newDeltaLatitude, 90.0f)); newDeltaLongitude = Math.Max(0.0f, Math.Min(newDeltaLongitude, 90.0f)); var region = new MKCoordinateRegion(mapView.Region.Center, new MKCoordinateSpan(newDeltaLatitude, newDeltaLongitude)); mapView.SetRegion(region, false); }