Ejemplo n.º 1
0
        public static string GenerateJsonBody(QueryCoordinates origin, QueryCoordinates destination)
        {
            var originarray = CoordinatesArray(origin);
            var destarray   = CoordinatesArray(destination);

            Destination[] origins = new Destination[1];
            origins[0] = new Destination
            {
                Latitude  = originarray[0],
                Longitude = originarray[1]
            };

            Destination[] destinations = new Destination[1];
            destinations[0] = new Destination
            {
                Latitude  = destarray[0],
                Longitude = destarray[1]
            };

            BodyDistanceMatrix body = new BodyDistanceMatrix()
            {
                Origins      = origins,
                Destinations = destinations,
                TravelMode   = "driving"
            };

            return(Serialize.ToJson(body));
        }
Ejemplo n.º 2
0
        public static async void ExecuteMethods()
        {
            EnderecoJson origin = await GetAddress("05314-000");

            EnderecoJson destination = await GetAddress("04180-112");

            QueryCoordinates coordinatesorigin = await GetCoordinates(GenerateUri(origin));

            QueryCoordinates coordinatesdestination = await GetCoordinates(GenerateUri(destination));

            var distancematrix = await PostDistance(GenerateJsonBody(coordinatesorigin, coordinatesdestination));

            var frete = await ValorDoFrete(GetDistance(distancematrix));

            Console.WriteLine(frete.ValorFrete);
        }
Ejemplo n.º 3
0
        private static async Task <QueryCoordinates> GetCoordinates(string address)
        {
            string responseData;
            var    baseAddress = new Uri("http://dev.virtualearth.net/REST/v1/");

            using (var httpClient = new HttpClient {
                BaseAddress = baseAddress
            })
            {
                using (var response = await httpClient.GetAsync("Locations/" + address + "?includeNeighborhood=1&maxResults=1&key=Av9IgsvQJRzGVg0lZV6QFzJJrsI9gW8EOq2vxtZCpYoqBvQtJZYowjyCOXg3YXlz"))
                {
                    responseData = await response.Content.ReadAsStringAsync();
                }
            }
            return(QueryCoordinates.FromJson(responseData));
        }
Ejemplo n.º 4
0
 public static double[] CoordinatesArray(QueryCoordinates coordinates)
 {
     double[] array = new double[2];
     foreach (var sets in coordinates.ResourceSets)
     {
         foreach (var a in sets.Resources)
         {
             int i = 0;
             foreach (var b in a.GeocodePoints)
             {
                 foreach (var c in b.Coordinates)
                 {
                     array[i] = c;
                     i++;
                 }
                 if (i == 2)
                 {
                     break;
                 }
             }
         }
     }
     return(array);
 }