Exemple #1
0
        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);
        }
        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);
        }
        /// <summary>
        /// Sets the map region to given Google Maps zoom level
        /// Will convert the zoom level to the correct MKCoordinateSpan
        /// Original Objective-C code found here: http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
        /// </summary>
        public static void SetCenterCoordinate(this MKMapView mapView, CLLocationCoordinate2D centerCoordinate, float zoomLevel, bool animated)
        {
            // clamp large numbers to 28
            zoomLevel = Math.Min(zoomLevel, 28);

            // use the zoom level to compute the region
            var span   = CoordinateSpanWithMapView(mapView, centerCoordinate, zoomLevel);
            var region = new MKCoordinateRegion(centerCoordinate, span);

            // set the region like normal
            mapView.SetRegion(region, animated);
        }
        private static float GetZoomLevelFromRegion(MKMapView mapView, MKCoordinateRegion region)
        {
            var centerPixelX = LongitudeToPixelSpaceX(region.Center.Longitude);
            var x            = LongitudeToPixelSpaceX(region.Center.Longitude - region.Span.LongitudeDelta);

            var topLeftPixelX = (x + centerPixelX) / 2;

            var scaledMapWidth = (centerPixelX - topLeftPixelX) * 2;

            var zoomScale = scaledMapWidth / mapView.Bounds.Size.Width;

            var zoomExponent = Math.Log(zoomScale, 2);

            return(20 - (int)zoomExponent);
        }
Exemple #6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var coordinate = new CoreLocation.CLLocationCoordinate2D(Double.Parse(centroSelected.Latitud), Double.Parse(centroSelected.Longitud));
            var region     = new MapKit.MKCoordinateRegion(coordinate, new MapKit.MKCoordinateSpan(0, 0));

            centroMapView.SetRegion(region, true);
            centroMapView.AddAnnotations(new MKPointAnnotation()
            {
                Title      = centroSelected.Nombre,
                Coordinate = new CLLocationCoordinate2D(Double.Parse(centroSelected.Latitud), Double.Parse(centroSelected.Longitud)),
            });

            mapCentroActionButton.Clicked += MapCentroActionItem_Clicked;
        }