protected override void DrawRouteInMap(IEnumerable <Geoposition> positions)
        {
            var nativeCoordinates = positions.Select(p => CoordinateConverter.ConvertToNative(p));

            _currentUserRoute = MKPolyline.FromCoordinates(nativeCoordinates.ToArray());

            _nativeMap.AddOverlay(_currentUserRoute);
        }
        public override async Task <IEnumerable <Geoposition> > CalculateRoute(Geoposition from, Geoposition to)
        {
            IEnumerable <Geoposition> result = Enumerable.Empty <Geoposition>();

            var nativeFrom = CoordinateConverter.ConvertToNative(from);
            var nativeTo   = CoordinateConverter.ConvertToNative(to);

            var userPlaceMark      = new MKPlacemark(nativeFrom, new Foundation.NSDictionary());
            var incidencePlaceMark = new MKPlacemark(nativeTo, new Foundation.NSDictionary());

            var sourceItem = new MKMapItem(userPlaceMark);
            var destItem   = new MKMapItem(incidencePlaceMark);

            var request = new MKDirectionsRequest
            {
                Source        = sourceItem,
                Destination   = destItem,
                TransportType = MKDirectionsTransportType.Automobile
            };

            var directions = new MKDirections(request);

            MKPolyline polyRoute = null;

            directions.CalculateDirections((response, error) =>
            {
                if (error != null)
                {
                    System.Diagnostics.Debug.WriteLine(error.LocalizedDescription);
                }
                else
                {
                    if (response.Routes.Any())
                    {
                        var firstRoute = response.Routes.First();
                        polyRoute      = firstRoute.Polyline;
                    }
                }
            });

            do
            {
                await Task.Delay(100);
            }while (directions.Calculating);

            if (polyRoute != null)
            {
                result = polyRoute.Points.Select(s =>
                {
                    CLLocationCoordinate2D coordinate = MKMapPoint.ToCoordinate(s);
                    return(CoordinateConverter.ConvertToAbstraction(coordinate));
                });
            }

            return(result);
        }
        public override IEnumerable <Geoposition> GetCurrentUserRoute()
        {
            var positions = _currentUserRoute?.Points.Select(r =>
            {
                var coord = MKMapPoint.ToCoordinate(r);
                return(CoordinateConverter.ConvertToAbstraction(coord));
            });

            return(positions);
        }
Example #4
0
        public override Geoposition GetCurrentUserPosition()
        {
            var userAnnotation = _nativeMap.Annotations.OfType <UserAnnotation>()
                                 .FirstOrDefault();

            if (userAnnotation == null)
            {
                System.Diagnostics.Debug.WriteLine("User annotation not found!");
                return(default(Geoposition));
            }

            return(CoordinateConverter.ConvertToAbstraction(userAnnotation.Coordinate));
        }
Example #5
0
        public override Geoposition GetResponderPosition(ResponderModel responder)
        {
            var responderAnnotation = _nativeMap.Annotations.OfType <ResponderAnnotation>()
                                      .Where(r => r.Responder.Id == responder.Id)
                                      .FirstOrDefault();

            if (responderAnnotation == null)
            {
                System.Diagnostics.Debug.WriteLine("Responder annotation not found!");
                return(default(Geoposition));
            }

            return(CoordinateConverter.ConvertToAbstraction(responderAnnotation.Coordinate));
        }