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);
                }
            });
        }
Exemplo n.º 2
0
        private void DidTapOnRoutingBtn(object sender, EventArgs e)
        {
            var origin = new MBWaypoint((CoreLocation.CLLocationCoordinate2D)userCoordinate,
                                        -1,
                                        "Your location");

            var destination = new MBWaypoint((CoreLocation.CLLocationCoordinate2D)destinationCoordinate,
                                             -1,
                                             "Destination");
            var options = new MBNavigationRouteOptions(
                new MBWaypoint[] { origin, destination },
                MBDirectionsProfileIdentifier.AutomobileAvoidingTraffic
                );

            MBDirections.SharedDirections.CalculateDirectionsWithOptions(
                options,
                (waypoints, routes, error) =>
            {
                if (routes == null || routes.Count == 0)
                {
                    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
                {
                    var locationManager = new MBSimulatedLocationManager(routes[0]);

                    var viewController = new MBNavigationViewController(routes[0], MBDirections.SharedDirections, null, locationManager);
                    PresentViewController(viewController, true, null);
                }
            });
        }