当前位置: 首页>>代码示例>>C#>>正文


C# MKMapView.SetRegion方法代码示例

本文整理汇总了C#中MKMapView.SetRegion方法的典型用法代码示例。如果您正苦于以下问题:C# MKMapView.SetRegion方法的具体用法?C# MKMapView.SetRegion怎么用?C# MKMapView.SetRegion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MKMapView的用法示例。


在下文中一共展示了MKMapView.SetRegion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ViewDidLoad

        public override void ViewDidLoad()
        {
            var mapView = new MKMapView();
            mapView.Delegate = new MyDelegate();
            View = mapView;

            base.ViewDidLoad();

            // ios7 layout
            if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
                EdgesForExtendedLayout = UIRectEdge.None;

            var secondViewModel = (SecondViewModel)ViewModel;
            var hanAnnotation = new ZombieAnnotation(secondViewModel.Han);

            mapView.AddAnnotation(hanAnnotation);

            mapView.SetRegion(MKCoordinateRegion.FromDistance(
                new CLLocationCoordinate2D(secondViewModel.Han.Location.Lat, secondViewModel.Han.Location.Lng),
                20000,
                20000), true);

            var button = new UIButton(UIButtonType.RoundedRect);
            button.Frame = new RectangleF(10, 10, 300, 40);
            button.SetTitle("move", UIControlState.Normal);
            Add(button);

            var set = this.CreateBindingSet<SecondView, Core.ViewModels.SecondViewModel>();
            set.Bind(hanAnnotation).For(a => a.Location).To(vm => vm.Han.Location);
            set.Bind(button).For("Title").To(vm => vm.Han.Location);
            set.Apply();
        }
开发者ID:KiranKumarAlugonda,项目名称:NPlus1DaysOfMvvmCross,代码行数:32,代码来源:SecondView.cs

示例2: ViewDidLoad

        public override void ViewDidLoad()
        {
            var mapView = new MKMapView();
            mapView.Delegate = new MyDelegate();
            View = mapView;

            base.ViewDidLoad();

            var firstViewModel = (FirstViewModel) ViewModel;
            var helenAnnotation = new ZombieAnnotation(firstViewModel.Helen);
            var keithAnnotation = new ZombieAnnotation(firstViewModel.Keith);

            mapView.AddAnnotation(helenAnnotation);
            mapView.AddAnnotation(keithAnnotation);

            mapView.SetRegion(MKCoordinateRegion.FromDistance(
                new CLLocationCoordinate2D(firstViewModel.Helen.Location.Lat, firstViewModel.Helen.Location.Lng),
                20000,
                20000), true);

            var button = new UIButton(UIButtonType.RoundedRect);
            button.Frame = new RectangleF(10, 10, 300, 40);
            button.SetTitle("move", UIControlState.Normal);
            Add(button);

            var set = this.CreateBindingSet<FirstView, Core.ViewModels.FirstViewModel>();
            set.Bind(button).To(vm => vm.MoveCommand);
            set.Bind(helenAnnotation).For(a => a.Location).To(vm => vm.Helen.Location);
            set.Bind(keithAnnotation).For(a => a.Location).To(vm => vm.Keith.Location);
            set.Apply();
        }
开发者ID:Jake-a-Lake,项目名称:NPlus1DaysOfMvvmCross,代码行数:31,代码来源:FirstView.cs

示例3: GeocoderViewControllerAdapter

 public GeocoderViewControllerAdapter(MvxViewController viewController, MKMapView mapView, Action<string> addressChanged)
     : base(viewController)
 {
     _geocoder = new CLGeocoder ();
     _addressChanged = addressChanged;
     mapView.RegionChanged += MapView_RegionChanged;
     mapView.SetRegion (new MapKit.MKCoordinateRegion (new CoreLocation.CLLocationCoordinate2D (45.5316085, -73.6227476), new MapKit.MKCoordinateSpan (0.01, 0.01)), animated: true);
 }
开发者ID:Costo,项目名称:Pizzapp,代码行数:8,代码来源:GeocoderViewControllerAdapter.cs

示例4: DidUpdateUserLocation

 public void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     Console.WriteLine("Weak Lat: {0}, Long: {1}, Alt: {2}", userLocation.Coordinate.Latitude, userLocation.Coordinate.Longitude, userLocation.Location.Altitude);
     currLocation = userLocation.Coordinate;
     if (firstLaunch) {
         mapView.SetRegion(MKCoordinateRegion.FromDistance(currLocation, 250, 250), true);
         firstLaunch = false;
     }
     else
         mapView.SetCenterCoordinate(currLocation, true);
 }
开发者ID:yingfangdu,项目名称:BNR,代码行数:11,代码来源:MapViewController.cs

示例5: CreateMapView

        void CreateMapView()
        {
            if (_mapView != null)
                return;

            _mapView = new MKMapView {ShowsUserLocation = true, GetViewForAnnotation = GetViewForAnnotation};

            View = _mapView;

            var visibleRegion = BuildVisibleRegion(_centerCoordinate);
            _mapView.SetRegion(visibleRegion, animated: true);
        }
开发者ID:samilamti,项目名称:ninja-locator,代码行数:12,代码来源:MapViewController.cs

示例6: MapOverlay

 public MapOverlay()
     : base(new RectangleF (0, 0, 144, 144))
 {
     map = new MKMapView (Bounds) {
         AutoresizingMask = UIViewAutoresizing.FlexibleDimensions,
         ShowsUserLocation = true,
         MapType = MKMapType.Satellite,
     };
     map.SetRegion (MKCoordinateRegion.FromDistance (new CLLocationCoordinate2D (47,-122), 1, 1), false);
     map.UserTrackingMode = MKUserTrackingMode.FollowWithHeading;
     Alpha = 0.5f;
     AddSubview (map);
 }
开发者ID:jorik041,项目名称:ARDemo,代码行数:13,代码来源:MapOverlay.cs

示例7: ZoomToUserLocation

        void ZoomToUserLocation(MKMapView mapView, MKUserLocation l)
        {
            var span = new MKCoordinateSpan
            {
                LatitudeDelta = 0.1,
                LongitudeDelta = 0.1,
            };

            var region = new MKCoordinateRegion
            {
                Center = l.Coordinate,
                Span = span,
            };

            mapView.SetRegion (region, true);
        }
开发者ID:hakonfjukstad,项目名称:Avgangsalarm,代码行数:16,代码来源:MapViewDelegate.cs

示例8: FinishedLaunching

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow (UIScreen.MainScreen.Bounds);

            // Create the 'Shows' tab.
            dvc1 = new DialogViewController (null) {
                Root = new RootElement ("") {
                    new Section (), new Section (), new Section (),
                    new Section () {
                        new StringElement ("House of Cards"),
                        new StringElement ("Game of Thrones"),
                        new StringElement ("Person of Interest")
                    }
                }
            };

            // Create the 'Games' tab.
            dvc2 = new DialogViewController (null) {
                Root = new RootElement ("") {
                    new Section (), new Section (), new Section (),
                    new Section () {
                        new StringElement ("Braid"),
                        new StringElement ("Super Meat Boy"),
                        new StringElement ("Fez")
                    }
                }
            };

            // Create the 'Atlanta' tab.
            var mapView = new MKMapView (UIScreen.MainScreen.Bounds);
            var atlanta = new MKCoordinateRegion (new CLLocationCoordinate2D (33.748893, -84.388046), new MKCoordinateSpan (0.35, 0.35));
            mapView.SetRegion (atlanta, false);
            mapViewController = new UIViewController ();
            mapViewController.View.Bounds = UIScreen.MainScreen.Bounds;
            mapViewController.View.AddSubview (mapView);

            // Create and display the floating tab bar controller.
            ftbc = new FloatingTabBarController () {
                TabTitles = new List<string> () { "Shows", "Games", "Atlanta" },
                ViewControllers = new List<UIViewController> () { dvc1, dvc2, mapViewController }
            };
            window.RootViewController = ftbc;
            window.MakeKeyAndVisible ();

            return true;
        }
开发者ID:jonnynezbo,项目名称:FloatingTabBar,代码行数:46,代码来源:AppDelegate.cs

示例9: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var map = new MKMapView(new RectangleF(20, 166, 280, 192));
            this.View.Add(map);
            map.ShowsUserLocation = true;
            map.MapType = MKMapType.Standard;
            map.Delegate = new MapViewDelegate();

            var location = new CLLocationCoordinate2D(ViewModel.Latitude, ViewModel.Longitude);
            //map.SetCenterCoordinate(location, true);
            map.SetRegion(new MKCoordinateRegion(location, new MKCoordinateSpan(0.1, 0.1)), true);

            var annotation = new MyAnnotation(
                                  location
                                  , ViewModel.SharedTextSource.GetText("AppTitle")
                                  , ViewModel.Name);
            map.AddAnnotationObject(annotation);


            Button1.SetImage(UIImage.FromFile("ConfResources/Images/appbar.link.png"), UIControlState.Normal);
            Button2.SetImage(UIImage.FromFile("ConfResources/Images/appbar.phone.png"), UIControlState.Normal);
            Button3.SetImage(UIImage.FromFile("ConfResources/Images/appbar.feature.email.rest.png"), UIControlState.Normal);

            this.AddBindings(new Dictionary<object, string>()
		                         {
                                     {Label1,"Text Name"}, 
                                     {Button1,"Title Address"},
                                     {Button2,"Title Phone"},
                                     {Button3,"Title Email"},
		                         });

            this.AddBindings(new Dictionary<object, string>()
		                         {
                                     {Button1,"TouchUpInside WebPageCommand"},
                                     {Button2,"TouchUpInside PhoneCommand"},
                                     {Button3,"TouchUpInside EmailCommand"},
		                         });

            NavigationItem.SetRightBarButtonItem(new UIBarButtonItem("Tweet", UIBarButtonItemStyle.Bordered, (sender, e) => ViewModel.DoShareGeneral()), false);
        }
开发者ID:ChebMami38,项目名称:MvvmCross-Tutorials,代码行数:42,代码来源:MapView.cs

示例10: ViewDidLoad

        public override void ViewDidLoad()
        {
            var mapView = new MKMapView();
            mapView.Delegate = new MyDelegate();
            View = mapView;

            base.ViewDidLoad();

            var thirdViewModel = (ThirdViewModel)ViewModel;
            _zombieManager = new ZombieManager(mapView);

            mapView.SetRegion(MKCoordinateRegion.FromDistance(
                new CLLocationCoordinate2D(51.4, 0.4),
                50000,
                50000), true);

            var set = this.CreateBindingSet<ThirdView, Core.ViewModels.ThirdViewModel>();
            set.Bind(_zombieManager).For(z => z.ItemsSource).To(vm => vm.Yarp);
            set.Apply();
        }
开发者ID:Jake-a-Lake,项目名称:NPlus1DaysOfMvvmCross,代码行数:20,代码来源:ThirdView.cs

示例11: ViewDidLoad

        public override void ViewDidLoad()
        {
            var mapView = new MKMapView();
            mapView.Delegate = new MyDelegate();
            View = mapView;

            base.ViewDidLoad();

            // ios7 layout
            if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
                EdgesForExtendedLayout = UIRectEdge.None;

            var thirdViewModel = (ThirdViewModel)ViewModel;
            _zombieManager = new ZombieManager(mapView);

            mapView.SetRegion(MKCoordinateRegion.FromDistance(
                new CLLocationCoordinate2D(51.4, 0.4),
                50000,
                50000), true);

            var set = this.CreateBindingSet<ThirdView, Core.ViewModels.ThirdViewModel>();
            set.Bind(_zombieManager).For(z => z.ItemsSource).To(vm => vm.Yarp);
            set.Apply();
        }
开发者ID:KiranKumarAlugonda,项目名称:NPlus1DaysOfMvvmCross,代码行数:24,代码来源:ThirdView.cs

示例12: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            mapView = new MKMapView()
            {
                ShowsUserLocation = true
            };

            labelDistance = new UILabel()
            {
                Frame = new RectangleF (0, 0, 320, 49),
                Lines = 2,
                BackgroundColor = UIColor.Black,
                TextColor = UIColor.White
            };

            var segmentedControl = new UISegmentedControl();
            var topOfSegement = View.Frame.Height - 120;
            segmentedControl.Frame = new RectangleF(20, topOfSegement, 282, 30);
            segmentedControl.InsertSegment("Map".GetText(), 0, false);
            segmentedControl.InsertSegment("Satellite".GetText(), 1, false);
            segmentedControl.InsertSegment("Hybrid".GetText(), 2, false);
            segmentedControl.SelectedSegment = 0;
            segmentedControl.ControlStyle = UISegmentedControlStyle.Bar;
            segmentedControl.TintColor = UIColor.DarkGray;

            segmentedControl.ValueChanged += delegate {
                if (segmentedControl.SelectedSegment == 0)
                    mapView.MapType = MonoTouch.MapKit.MKMapType.Standard;
                else if (segmentedControl.SelectedSegment == 1)
                    mapView.MapType = MonoTouch.MapKit.MKMapType.Satellite;
                else if (segmentedControl.SelectedSegment == 2)
                    mapView.MapType = MonoTouch.MapKit.MKMapType.Hybrid;
            };

            mapView.Delegate = new MapViewDelegate(this);

            // Set the web view to fit the width of the app.
            mapView.SizeToFit();

            // Reposition and resize the receiver
            mapView.Frame = new RectangleF (0, 50, View.Frame.Width, View.Frame.Height - 100);

            MKCoordinateSpan span = new MKCoordinateSpan(0.01,0.01);
            MKCoordinateRegion region = new MKCoordinateRegion(ConferenceLocation,span);
            mapView.SetRegion(region, true);

            ConferenceAnnotation a = new ConferenceAnnotation(ConferenceLocation
                                , "CodeCampSDQ"
                                , "INTEC"
                              );
            mapView.AddAnnotationObject(a);

            locationManager = new CLLocationManager();
            locationManager.Delegate = new LocationManagerDelegate(mapView, this);
            locationManager.StartUpdatingLocation();

            // Add the table view as a subview
            View.AddSubview(mapView);
            View.AddSubview(labelDistance);
            View.AddSubview(segmentedControl);

            // Add the 'info' button to flip
            var flipButton = UIButton.FromType(UIButtonType.InfoLight);
            flipButton.Frame = new RectangleF(290,17,20,20);
            flipButton.Title (UIControlState.Normal);
            flipButton.TouchDown += delegate {
                _mfvc.Flip();
            };
            View.AddSubview(flipButton);
        }
开发者ID:megsoftconsulting,项目名称:MonkeySpace,代码行数:71,代码来源:MapViewController.cs

示例13: 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);
            }
        }
开发者ID:nicwise,项目名称:londonbikeapp,代码行数:101,代码来源:MapViewController.cs

示例14: DidUpdateUserLocation

			/// <summary>
			/// Center the map when the user is located
			/// </summary>
			public override void DidUpdateUserLocation (MKMapView mapView, MKUserLocation userLocation)
			{
				if (userLocation != null) {
					var span = new MKCoordinateSpan (15, 15);
					var region = new MKCoordinateRegion (userLocation.Coordinate, span);
					mapView.SetRegion (region, true);
				}
			}
开发者ID:felipecembranelli,项目名称:MyXamarinSamples,代码行数:11,代码来源:MainMapController.cs

示例15: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            mapView = new MKMapView()
            {
                ShowsUserLocation = true
            };

            labelDistance = new UILabel()
            {
                Frame = new RectangleF (0, 0, 320, 49),
                Lines = 2,
                BackgroundColor = UIColor.Black,
                TextColor = UIColor.White
            };

            var segmentedControl = new UISegmentedControl();
            var topOfSegement = View.Frame.Height - 120;
            segmentedControl.Frame = new RectangleF(20, topOfSegement, 282, 30);
            segmentedControl.InsertSegment("Map", 0, false);
            segmentedControl.InsertSegment("Satellite", 1, false);
            segmentedControl.InsertSegment("Hybrid", 2, false);
            segmentedControl.SelectedSegment = 0;
            segmentedControl.ControlStyle = UISegmentedControlStyle.Bar;
            segmentedControl.TintColor = UIColor.DarkGray;

            if(UIDevice.CurrentDevice.CheckSystemVersion(6,0))
                segmentedControl.InsertSegment ("Directions", 3, false);

            segmentedControl.ValueChanged += delegate {
                if (segmentedControl.SelectedSegment == 0)
                    mapView.MapType = MonoTouch.MapKit.MKMapType.Standard;
                else if (segmentedControl.SelectedSegment == 1)
                    mapView.MapType = MonoTouch.MapKit.MKMapType.Satellite;
                else if (segmentedControl.SelectedSegment == 2)
                    mapView.MapType = MonoTouch.MapKit.MKMapType.Hybrid;
                else if (segmentedControl.SelectedSegment == 3) {
                    var conferenceMapItem = new MKMapItem(new MKPlacemark(ConferenceLocation, null));
                    conferenceMapItem.Name = "MonkeySpace";

                    var conferenceHotel = new MKMapItem(new MKPlacemark(new CLLocationCoordinate2D(42.36346, -71.0863), null));
                    conferenceHotel.Name = "MonkeySpace Hotel";

                    var mapItems = new MKMapItem[] { conferenceMapItem, conferenceHotel };
                    MKMapItem.OpenMaps(mapItems, new MKLaunchOptions() {
                        DirectionsMode = MKDirectionsMode.Walking
                    });
                }
            };

            mapView.Delegate = new MapViewDelegate(this);

            // Set the web view to fit the width of the app.
            mapView.SizeToFit();

            // Reposition and resize the receiver
            mapView.Frame = new RectangleF (0, 50, View.Frame.Width, View.Frame.Height - 100);

            MKCoordinateSpan span = new MKCoordinateSpan(0.01,0.01);
            MKCoordinateRegion region = new MKCoordinateRegion(ConferenceLocation,span);
            mapView.SetRegion(region, true);

            ConferenceAnnotation a = new ConferenceAnnotation(ConferenceLocation
                                , "MonkeySpace"
                                , "NERD Center"
                              );
            mapView.AddAnnotationObject(a);

            locationManager = new CLLocationManager();
            locationManager.Delegate = new LocationManagerDelegate(mapView, this);
            locationManager.StartUpdatingLocation();

            // Add the table view as a subview
            View.AddSubview(mapView);
            View.AddSubview(labelDistance);
            View.AddSubview(segmentedControl);

            // Add the 'info' button to flip
            var flipButton = UIButton.FromType(UIButtonType.InfoLight);
            flipButton.Frame = new RectangleF(290,17,20,20);
            flipButton.Title (UIControlState.Normal);
            flipButton.TouchDown += delegate {
                _mfvc.Flip();
            };
            View.AddSubview(flipButton);
        }
开发者ID:chrisntr,项目名称:MonkeySpace,代码行数:86,代码来源:MapViewController.cs


注:本文中的MKMapView.SetRegion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。