Beispiel #1
0
        public virtual async Task <List <T> > GetItemsAsync(SystemSearchParameter systemSearch)
        {
            var accesstoken = await RequestProvider.CreateHttpClient().ReadSystemAccessToken();

            return(await RequestProvider.GetAsync <List <T> >(RunUrl, systemSearch, accesstoken));

            // return  await Task.Run< List<T>>(() => JsonConvert.DeserializeObject<List<T>>(readresult)); ;
        }
        private async Task <PolylineOptions> RequestRoutePolyline(Geoposition from, Geoposition to)
        {
            // Origin of route
            string originQueryParam = $"origin={from.Latitude.ToString(CultureInfo.InvariantCulture)},{from.Longitude.ToString(CultureInfo.InvariantCulture)}";

            // Destination of route
            string destinationQueryParam = $"destination={to.Latitude.ToString(CultureInfo.InvariantCulture)},{to.Longitude.ToString(CultureInfo.InvariantCulture)}";

            // Sensor enabled
            string sensor = "sensor=false";

            // Auth
            string key = "key=AIzaSyDDKvhUqz1fnEImpiC8zrflraQdgo8PaMo";

            RootRouteModel routeData = default(RootRouteModel);

            try
            {
                // Building the parameters to the web service
                string parameters = string.Join("&", new[] { originQueryParam, destinationQueryParam, sensor, key });

                UriBuilder uri = new UriBuilder("https://maps.googleapis.com/maps/api/directions/json");
                uri.Query = parameters;

                var requestProvider = new RequestProvider();
                routeData = await requestProvider.GetAsync <RootRouteModel>(uri.ToString());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Error calling routes api from google: {ex}");
            }

            PolylineOptions polylineOptions = new PolylineOptions();

            if (routeData?.Routes?.Any() == true)
            {
                var route = routeData.Routes.FirstOrDefault();

                var polylinePoints = route.Polyline.Points;

                foreach (var step in route.Steps)
                {
                    var points = DecodePolyline(polylinePoints);

                    foreach (var point in points)
                    {
                        polylineOptions.Add(point);
                    }
                }
            }

            return(polylineOptions);
        }
Beispiel #3
0
 public async Task <List <TestResponseGET> > GetTestAsync()
 {
     try
     {
         var uri = ApiResources.Test_GETAPI;
         return(await RequestProvider.GetAsync <List <TestResponseGET> >(uri));
     }
     catch (Exception)
     {
         return(null);
     }
 }
        public async Task <IEnumerable <Position> > GetPositionsForAddressAsync(string address)
        {
            if (!string.IsNullOrEmpty(address))
            {
                // Origin of route
                string addressQueryParam = $"address={WebUtility.UrlEncode(address)}";

                // Auth
                string key = $"key={AppSettings.GoogleMapsGeocodeAPIKey}";

                GeoCodeResult geoCodeData = default(GeoCodeResult);
                try
                {
                    // Building the parameters to the web service
                    string parameters = string.Join("&", new[] { addressQueryParam, key });

                    UriBuilder uri = new UriBuilder("https://maps.googleapis.com/maps/api/geocode/json");
                    uri.Query = parameters;

                    var requestProvider = new RequestProvider();
                    geoCodeData = await requestProvider.GetAsync <GeoCodeResult>(uri.ToString());
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine($"Error calling routes api from google: {ex}");
                    return(null);
                }

                if ("OK".Equals(geoCodeData?.Status, StringComparison.CurrentCultureIgnoreCase) &&
                    geoCodeData?.Results != null &&
                    geoCodeData.Results.Any())
                {
                    Collection <Position> result = new Collection <Position>();

                    foreach (var geoCodePosition in geoCodeData.Results)
                    {
                        if (geoCodePosition?.Geometry?.Location != null)
                        {
                            result.Add(new Position(
                                           geoCodePosition.Geometry.Location.Latitude,
                                           geoCodePosition.Geometry.Location.Longitude));
                        }
                    }

                    return(result);
                }
            }

            return(null);
        }
Beispiel #5
0
        private async Task Initialization()
        {
            try
            {
                var fiatResult = await _requestProvider.GetAsync <Fiat[]>(GlobalSetting.Instance.FiatEndpoint);

                {
                    decimal.TryParse(fiatResult[0].PriceUsd, out _usdPrice);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"--- Error: {e.StackTrace}");
            }
        }
Beispiel #6
0
        private async Task <PolylineOptions> RequestRoutePolyline(CarPool.Clients.Core.Maps.Model.RouteModel route)
        {
            // Origin of route
            string originQueryParam = $"origin={route.From.Latitude.ToString(CultureInfo.InvariantCulture)},{route.From.Longitude.ToString(CultureInfo.InvariantCulture)}";

            // Destination of route
            string destinationQueryParam = $"destination={route.To.Latitude.ToString(CultureInfo.InvariantCulture)},{route.To.Longitude.ToString(CultureInfo.InvariantCulture)}";

            // route waypoints
            if (route.WayPoints != null && route.WayPoints.Any())
            {
                destinationQueryParam += "&waypoints=optimize:true";
                foreach (var point in route.WayPoints)
                {
                    destinationQueryParam += $"|{point.Latitude.ToString(CultureInfo.InvariantCulture)},{point.Longitude.ToString(CultureInfo.InvariantCulture)}";
                }
            }

            // Sensor enabled
            string sensor = "sensor=false";

            // Auth
            // TODO sacar
            string key = $"key={AppSettings.GoogleMapsAPIKey}";

            RootRouteModel routeData = default(RootRouteModel);

            try
            {
                // Building the parameters to the web service
                string parameters = string.Join("&", new[] { originQueryParam, destinationQueryParam, sensor, key });

                UriBuilder uri = new UriBuilder("https://maps.googleapis.com/maps/api/directions/json");
                uri.Query = parameters;

                var requestProvider = new RequestProvider();
                routeData = await requestProvider.GetAsync <RootRouteModel>(uri.ToString());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Error calling routes api from google: {ex}");
            }

            PolylineOptions polylineOptions = new PolylineOptions();

            if (routeData?.Routes?.Any() == true)
            {
                var serviceRoute = routeData.Routes.FirstOrDefault();

                var polylinePoints = serviceRoute.Polyline.Points;

                double totalDistance = 0, totalTime = 0;
                var    points = DecodePolyline(polylinePoints);

                foreach (var point in points)
                {
                    polylineOptions.Add(point);
                }

                foreach (var step in serviceRoute.Steps)
                {
                    totalDistance += step?.Distance?.Value ?? 0;
                    totalTime     += step?.Duration?.Value ?? 0;
                }

                route.Distance = totalDistance;
                route.Duration = totalTime / 60;
            }

            return(polylineOptions);
        }