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

            map = new MGLMapView(View.Bounds);
            map.AutoresizingMask = new UIViewAutoresizing();
            map.WeakDelegate     = this;
            View.AddSubview(map);

            map.ShowsUserLocation = true;
            map.SetUserTrackingMode(MGLUserTrackingMode.Follow, true);


            UILongPressGestureRecognizer longPress = new UILongPressGestureRecognizer(DidLongPressOnMap);

            map.AddGestureRecognizer(longPress);

            MBWaypoint[] ways = new MBWaypoint[2];
            ways[0] = new MBWaypoint(new CLLocationCoordinate2D(45.622073, -73.824223), -1, "origin");
            ways[1] = new MBWaypoint(new CLLocationCoordinate2D(45.626764, -73.825742), -1, "destination");
            MBNavigationRouteOptions options = new MBNavigationRouteOptions(ways, MBDirectionsProfileIdentifier.Automobile);


            MBDirections.SharedDirections.CalculateDirectionsWithOptions(options, (way, routes, error) =>
            {
                if (routes.Length == 0 || routes == null)
                {
                    string errorMessage = "No routes found";
                    if (error != null)
                    {
                        errorMessage = error.LocalizedDescription;
                    }
                    var alert = UIAlertController.Create("Error", errorMessage, UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("Dismiss", UIAlertActionStyle.Cancel, null));
                    PresentViewController(alert, true, null);
                }
                else
                {
                    MBRoute route = routes[0];
                    MBNavigationService navigationService = new MBNavigationService(route, MBDirections.SharedDirections, null, null, MBNavigationSimulationOptions.Always, null);
                    //MBNavigationOptions navigationOptions = new MBNavigationOptions(null, navigationService, null, null, null);
                    MBNavigationViewController navigationViewController = new MBNavigationViewController(route, null);

                    PresentViewController(navigationViewController, true, null);
                }
            });
        }
예제 #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            mapView = new MGLMapView()
            {
                UserTrackingMode = MGLUserTrackingMode.Follow,
                WeakDelegate     = this
            };
            View.AddSubview(mapView);

            var bottomToolbar = new UIToolbar()
            {
                Tag = 101
            };

            View.AddSubview(bottomToolbar);
            var items = new List <UIBarButtonItem>();

            var bottomMessageLbl = new UILabel()
            {
                Text  = "Long press to\nselect destination",
                Lines = 2
            };

            bottomMessageLbl.SizeToFit();
            var messageItem = new UIBarButtonItem()
            {
                CustomView = bottomMessageLbl
            };

            items.Add(messageItem);
            items.Add(new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace));
            routingItem = new UIBarButtonItem("Show navigation", UIBarButtonItemStyle.Plain, DidTapOnRoutingBtn)
            {
                Enabled = false
            };
            items.Add(routingItem);

            bottomToolbar.SetItems(items.ToArray(), false);

            var longPress = new UILongPressGestureRecognizer(DidLongPressOnMap);

            mapView.AddGestureRecognizer(longPress);
        }