public void GetQueryStringParametersWhenRegionTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key     = "key",
                Origins = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Destinations = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Region = "region"
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var region         = queryStringParameters.FirstOrDefault(x => x.Key == "region");
            var regionExpected = request.Region;

            Assert.IsNotNull(region);
            Assert.AreEqual(regionExpected, region.Value);
        }
Exemple #2
0
        public void DistanceMatrixWhenDepartureTimeTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key           = this.ApiKey,
                Origins       = new[] { new Location(40.7141289, -73.9614074) },
                Destinations  = new[] { new Location("185 Broadway Ave, Manhattan, NY, USA") },
                DepartureTime = DateTime.Now
            };
            var response = GoogleMaps.DistanceMatrix.Query(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(Status.Ok, response.Status);

            var row = response.Rows.FirstOrDefault();

            Assert.IsNotNull(row);

            var element = row.Elements.FirstOrDefault();

            Assert.IsNotNull(element);
            Assert.AreEqual(Status.Ok, element.Status);
            Assert.IsNotNull(element.Distance.Value);
            Assert.IsNotNull(element.Duration.Value);
            Assert.IsNotNull(element.DurationInTraffic.Value);
        }
Exemple #3
0
        public void DistanceMatrixWhenAvoidWayTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key           = this.ApiKey,
                Origins       = new[] { new Location(40.7141289, -73.9614074) },
                Destinations  = new[] { new Location("185 Broadway Ave, Manhattan, NY, USA") },
                Avoid         = AvoidWay.Tolls | AvoidWay.Highways,
                DepartureTime = DateTime.Now
            };

            var response = GoogleMaps.DistanceMatrix.Query(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(Status.Ok, response.Status);
            Assert.IsNotNull(response.OriginAddresses.FirstOrDefault());
            Assert.IsNotNull(response.DestinationAddresses.FirstOrDefault());

            var row = response.Rows.FirstOrDefault();

            Assert.IsNotNull(row);

            var element = row.Elements.FirstOrDefault();

            Assert.IsNotNull(element);
            Assert.AreEqual(Status.Ok, element.Status);
            Assert.IsNotNull(element.Distance.Text);
            Assert.AreEqual(5857.00, element.Distance.Value, 500.00);
            Assert.IsNotNull(element.Duration.Text);
            Assert.AreEqual(1509.00, element.Duration.Value, 100.00);
        }
        public void ShouldReturnValidValueWhenOneOriginAndOneDestinationsSpeciefed()
        {
            var request = new DistanceMatrixRequest
            {
                Origins      = new[] { "49.64265,12.50088" },
                Destinations = new[] { "53.64308,10.52726" }
            };

            var result = GoogleMaps.DistanceMatrix.Query(request);

            if (result.Status == DistanceMatrixStatusCodes.OVER_QUERY_LIMIT)
            {
                Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit.");
            }
            Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status);
            CollectionAssert.AreEqual(
                new [] { "Alter Sirksfelder Weg 7, 23881 Koberg, Germany" },
                result.DestinationAddresses);
            CollectionAssert.AreEqual(
                new[] { "Pilsener Str. 16, 92726 Waidhaus, Germany" },
                result.OriginAddresses);
            Assert.AreEqual(DistanceMatrixElementStatusCodes.OK, result.Rows.First().Elements.First().Status);
            Assert.IsNotNull(result.Rows.First().Elements.First().Distance);
            Assert.IsNotNull(result.Rows.First().Elements.First().Duration);
        }
        public void ShouldPassRawDataToOnRawResponseRecivied()
        {
            var request = new DistanceMatrixRequest
            {
                ApiKey       = ApiKey,
                Origins      = new[] { "placeholder" },
                Destinations = new[] { "3,4" },
            };

            var rawData = new byte[0];

            RawResponseReciviedDelegate onRawResponseRecivied = data => rawData = data;

            GoogleMaps.DistanceMatrix.OnRawResponseRecivied += onRawResponseRecivied;

            try
            {
                var result = GoogleMaps.DistanceMatrix.Query(request);
                if (result.Status == DistanceMatrixStatusCodes.OVER_QUERY_LIMIT)
                {
                    Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit.");
                }
                Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status);
                CollectionAssert.IsNotEmpty(rawData);
            }
            finally
            {
                GoogleMaps.DistanceMatrix.OnRawResponseRecivied -= onRawResponseRecivied;
            }
        }
        public void DistanceMatrixTest()
        {
            var origin1      = new Address("285 Bedford Ave, Brooklyn, NY, USA");
            var origin2      = new Address("1 Broadway Ave, Manhattan, NY, USA");
            var destination1 = new Address("185 Broadway Ave, Manhattan, NY, USA");
            var destination2 = new Address("200 Bedford Ave, Brooklyn, NY, USA");

            var request = new DistanceMatrixRequest
            {
                Key     = this.ApiKey,
                Origins = new[]
                {
                    new LocationEx(origin1),
                    new LocationEx(origin2)
                },
                Destinations = new[]
                {
                    new LocationEx(destination1),
                    new LocationEx(destination2)
                }
            };

            var result = GoogleMaps.DistanceMatrix.Query(request);

            Assert.IsNotNull(result);
            Assert.AreEqual(Status.Ok, result.Status);
        }
        public void DistanceMatrixWhenAsyncAndCancelledTest()
        {
            var origin      = new Address("285 Bedford Ave, Brooklyn, NY, USA");
            var destination = new Address("185 Broadway Ave, Manhattan, NY, USA");
            var request     = new DistanceMatrixRequest
            {
                Key     = this.ApiKey,
                Origins = new[]
                {
                    new LocationEx(origin)
                },
                Destinations = new[]
                {
                    new LocationEx(destination)
                }
            };
            var cancellationTokenSource = new CancellationTokenSource();
            var task = GoogleMaps.DistanceMatrix.QueryAsync(request, cancellationTokenSource.Token);

            cancellationTokenSource.Cancel();

            var exception = Assert.Throws <OperationCanceledException>(() => task.Wait(cancellationTokenSource.Token));

            Assert.IsNotNull(exception);
            Assert.AreEqual(exception.Message, "The operation was canceled.");
        }
        public void ShouldReplaceUriViaOnUriCreated()
        {
            var request = new DistanceMatrixRequest
            {
                ApiKey       = ApiKey,
                Origins      = new[] { "placeholder" },
                Destinations = new[] { "3,4" },
            };

            UriCreatedDelegate onUriCreated = delegate(Uri uri)
            {
                var builder = new UriBuilder(uri);
                builder.Query = builder.Query.Replace("placeholder", "1,2");
                return(builder.Uri);
            };

            GoogleMaps.DistanceMatrix.OnUriCreated += onUriCreated;

            try
            {
                var result = GoogleMaps.DistanceMatrix.Query(request);

                AssertInconclusive.NotExceedQuota(result);
                Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage);
                Assert.AreEqual("1,2", result.OriginAddresses.First());
            }
            finally
            {
                GoogleMaps.DistanceMatrix.OnUriCreated -= onUriCreated;
            }
        }
        public void ShouldPassRawDataToOnRawResponseRecivied()
        {
            var request = new DistanceMatrixRequest
            {
                ApiKey       = ApiKey,
                Origins      = new[] { "placeholder" },
                Destinations = new[] { "3,4" },
            };

            var rawData = new byte[0];

            RawResponseReciviedDelegate onRawResponseRecivied = data => rawData = data;

            GoogleMaps.DistanceMatrix.OnRawResponseRecivied += onRawResponseRecivied;

            try
            {
                var result = GoogleMaps.DistanceMatrix.Query(request);

                AssertInconclusive.NotExceedQuota(result);
                Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage);
                CollectionAssert.IsNotEmpty(rawData);
            }
            finally
            {
                GoogleMaps.DistanceMatrix.OnRawResponseRecivied -= onRawResponseRecivied;
            }
        }
        public void GetQueryStringParametersWhenTravelModeTransitAndTransitRoutingPreferenceTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key     = "key",
                Origins = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Destinations = new[]
                {
                    new LocationEx(new Address("address"))
                },
                TravelMode  = TravelMode.Transit,
                TransitMode = TransitMode.Subway | TransitMode.Rail,
                TransitRoutingPreference = TransitRoutingPreference.Fewer_Transfers
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var transitRoutingPreference         = queryStringParameters.FirstOrDefault(x => x.Key == "transit_routing_preference");
            var transitRoutingPreferenceExpected = request.TransitRoutingPreference.ToString().ToLower();

            Assert.IsNotNull(transitRoutingPreference);
            Assert.AreEqual(transitRoutingPreferenceExpected, transitRoutingPreference.Value);
        }
        public void GetQueryStringParametersWhenChannelTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key     = "key",
                Origins = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Destinations = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Channel = "channel"
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var channel         = queryStringParameters.FirstOrDefault(x => x.Key == "channel");
            var channelExpected = request.Channel;

            Assert.IsNotNull(channel);
            Assert.AreEqual(channelExpected, channel.Value);
        }
        public void GetQueryStringParametersWhenTravelModeDrivingAndDepartureTimeAndTrafficModelTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key     = "key",
                Origins = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Destinations = new[]
                {
                    new LocationEx(new Address("address"))
                },
                TravelMode    = TravelMode.Driving,
                DepartureTime = DateTime.UtcNow.AddHours(1),
                TrafficModel  = TrafficModel.Best_Guess
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var departureTime         = queryStringParameters.FirstOrDefault(x => x.Key == "departure_time");
            var departureTimeExpected = request.DepartureTime.GetValueOrDefault().DateTimeToUnixTimestamp().ToString(CultureInfo.InvariantCulture);

            Assert.IsNotNull(departureTime);
            Assert.AreEqual(departureTimeExpected, departureTime.Value);

            var trafficModel         = queryStringParameters.FirstOrDefault(x => x.Key == "traffic_model");
            var trafficModelExpected = request.TrafficModel.ToString().ToLower();

            Assert.IsNotNull(trafficModel);
            Assert.AreEqual(trafficModelExpected, trafficModel.Value);
        }
        public void GetQueryStringParametersWhenTravelModeTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key     = "key",
                Origins = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Destinations = new[]
                {
                    new LocationEx(new Address("address"))
                },
                TravelMode = TravelMode.Bicycling
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var mode         = queryStringParameters.FirstOrDefault(x => x.Key == "mode");
            var modeExpected = request.TravelMode.ToString().ToLower();

            Assert.IsNotNull(mode);
            Assert.AreEqual(modeExpected, mode.Value);
        }
        public void GetQueryStringParametersWhenAvoidTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key     = "key",
                Origins = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Destinations = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Avoid = AvoidWay.Highways | AvoidWay.Ferries
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var avoid         = queryStringParameters.FirstOrDefault(x => x.Key == "avoid");
            var avoidExpected = request.Avoid.ToEnumString('|');

            Assert.IsNotNull(avoid);
            Assert.AreEqual(avoidExpected, avoid.Value);
        }
Exemple #15
0
        public static int GetDistance(List <string> locations)
        {
            int distance = 0;

            GoogleSigned.AssignAllServices(new GoogleSigned(apiKey));

            var request = new DistanceMatrixRequest();

            foreach (string s in locations)
            {
                request.AddOrigin(new Google.Maps.Location(s));
                request.AddDestination(new Google.Maps.Location(s));
            }
            request.Units = Units.imperial;

            var response = new DistanceMatrixService().GetResponse(request);

            if (response.Status == ServiceResponseStatus.Ok && response.Rows.Count() > 0)
            {
                for (int i = 0; i < response.Rows.Length - 1; i++)
                {
                    distance += (int)response.Rows[i].Elements[i + 1].distance.Value;
                }
            }

            return(distance);
        }
        private async void button_Check_Click(object sender, EventArgs e)
        {
            // Check if Pincode Selected
            if (comboBox_Pincode.SelectedIndex < 0)
            {
                MessageBox.Show("Invalid Pincode!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Calculate & Populate Duration & Sort Seller List
            DistanceMatrixRequest y = new DistanceMatrixRequest();

            y.ApiKey  = Program.szGoogleMapsAPI_key;
            y.Origins = new string[] { comboBox_Pincode.Text };
            y.Mode    = DistanceMatrixTravelModes.driving;
            List <string> Destinations = new List <string>();

            foreach (DataGridViewRow x in dataGridView_SellerList.Rows)
            {
                CSeller_Inventory temp = (CSeller_Inventory)(x.Cells["extra_1"].Value);
                Destinations.Add(temp.pincode.ToString());
            }
            y.Destinations = Destinations.ToArray <string>();
            DistanceMatrixResponse z = await GoogleMapsApi.GoogleMaps.DistanceMatrix.QueryAsync(y);

            for (int i = 0; i < z.Rows.ElementAt <Row>(0).Elements.Count <Element>(); ++i)
            {
                Element x = z.Rows.ElementAt <Row>(0).Elements.ElementAt <Element>(i);
                dataGridView_SellerList.Rows[i].Cells["shipping_time"].Value = (x.Duration.Value.Days + 1) + " Day(s) " + (x.Duration.Value.Hours) + " Hour(s)";
            }
            dataGridView_SellerList.Sort(dataGridView_SellerList.Columns["shipping_time"], ListSortDirection.Ascending);
        }
Exemple #17
0
        public void DistanceMatrixWhenCoordinatesTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key          = this.ApiKey,
                Origins      = new[] { new Location(40.7141289, -73.9614074) },
                Destinations = new[] { new Location(40.71049396441609, -74.0098624305255) }
            };
            var response = GoogleMaps.DistanceMatrix.Query(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(Status.Ok, response.Status);
            Assert.IsNotNull(response.OriginAddresses.FirstOrDefault());
            Assert.IsNotNull(response.DestinationAddresses.FirstOrDefault());

            var row = response.Rows.FirstOrDefault();

            Assert.IsNotNull(row);

            var element = row.Elements.FirstOrDefault();

            Assert.IsNotNull(element);
            Assert.AreEqual(Status.Ok, element.Status);
            Assert.IsNotNull(element.Distance.Text);
            Assert.AreEqual(8258.00, element.Distance.Value, 5000.00);
            Assert.IsNotNull(element.Duration.Text);
            Assert.AreEqual(1135.00, element.Duration.Value, 500.00);
        }
Exemple #18
0
        public double CalculaDistanciaEntreDoisPontos(double lat1, double long1, double lat2, double long2)
        {
            DistanceMatrixRequest request = new DistanceMatrixRequest();

            request.AddOrigin(new Waypoint {
                Position = new LatLng(lat1, long1)
            });
            request.AddDestination(new Waypoint {
                Position = new LatLng(lat2, long2)
            });
            request.Sensor = false;

            try
            {
                DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request);

                if (response.Status == ServiceResponseStatus.Ok)
                {
                    int distInteger;

                    if (Int32.TryParse(response.Rows[0].Elements[0].distance.Value, out distInteger))
                    {
                        return((double)distInteger / 1000);
                    }
                }
            }
            catch { }

            return(0.0);
        }
        public void DistanceMatrixWhenTravelModeTransitAndArrivalTimeTest()
        {
            var origin      = new Address("285 Bedford Ave, Brooklyn, NY, USA");
            var destination = new Address("185 Broadway Ave, Manhattan, NY, USA");
            var request     = new DistanceMatrixRequest
            {
                Key     = this.ApiKey,
                Origins = new[]
                {
                    new LocationEx(origin)
                },
                Destinations = new[]
                {
                    new LocationEx(destination)
                },
                TravelMode  = TravelMode.Driving,
                ArrivalTime = DateTime.UtcNow.AddHours(1),
                TransitRoutingPreference = TransitRoutingPreference.Fewer_Transfers
            };

            var result = GoogleMaps.DistanceMatrix.Query(request);

            Assert.IsNotNull(result);
            Assert.AreEqual(Status.Ok, result.Status);
        }
Exemple #20
0
        public void UpdateDistanceMatrix()
        {
            var origins = new List <Location>()
            {
                homeAddress.AsLocation()
            };
            var destinations = new List <Location>()
            {
                homeAddress.AsLocation()
            };

            origins.AddRange(from customer in customersList select customer.AsLocation());
            destinations.AddRange(from customer in customersList select customer.AsLocation());

            DistanceMatrixRequest request = new DistanceMatrixRequest()
            {
                WaypointsOrigin      = origins,
                WaypointsDestination = destinations
            };
            var response = new DistanceMatrixService().GetResponse(request);

            if (response.Status == 0)
            {
                throw new Exception("Invalid address");
            }

            distanceMatrix = response.Rows;
        }
        public void DistanceMatrixWhenCoordinateAndHeadingTest()
        {
            var origin = new CoordinateEx(55.7237480, 12.4208282)
            {
                Heading = 90
            };
            var destination = new CoordinateEx(55.72672682, 12.407996582)
            {
                Heading = 90
            };
            var request = new DistanceMatrixRequest
            {
                Key     = this.ApiKey,
                Origins = new[]
                {
                    new LocationEx(origin)
                },
                Destinations = new[]
                {
                    new LocationEx(destination)
                }
            };

            var result = GoogleMaps.DistanceMatrix.Query(request);

            Assert.IsNotNull(result);
            Assert.AreEqual(Status.Ok, result.Status);
        }
Exemple #22
0
        //Gebaseerd op twee SimpleWaypoints wordt de afstand berekent tussen die twee punten een een double van die afstand in kilometers teruggegeven
        public async Task <double> TravelDistance(SimpleWaypoint originCoor, SimpleWaypoint destinationCoor)
        {
            List <SimpleWaypoint> origin      = new List <SimpleWaypoint>();
            List <SimpleWaypoint> destination = new List <SimpleWaypoint>();

            origin.Add(originCoor);
            destination.Add(destinationCoor);

            DistanceMatrixRequest distance = new DistanceMatrixRequest();

            distance.Origins      = origin;
            distance.Destinations = destination;
            distance.BingMapsKey  = bingMapKey;
            distance.TravelMode   = TravelModeType.Driving;

            var response = await distance.Execute();

            if (response != null &&
                response.ResourceSets != null &&
                response.ResourceSets.Length > 0 &&
                response.ResourceSets[0].Resources != null &&
                response.ResourceSets[0].Resources.Length > 0)
            {
                DistanceMatrix result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.DistanceMatrix;
                return(result.Results[0].TravelDistance);
            }
            return(-1);
        }
        public void ShouldReplaceUriViaOnUriCreated()
        {
            var request = new DistanceMatrixRequest
            {
                ApiKey       = ApiKey,
                Origins      = new[] { "placeholder" },
                Destinations = new[] { "3,4" },
            };

            UriCreatedDelegate onUriCreated = delegate(Uri uri)
            {
                var builder = new UriBuilder(uri);
                builder.Query = builder.Query.Replace("placeholder", "1,2");
                return(builder.Uri);
            };

            GoogleMaps.DistanceMatrix.OnUriCreated += onUriCreated;

            try
            {
                var result = GoogleMaps.DistanceMatrix.Query(request);
                if (result.Status == DistanceMatrixStatusCodes.OVER_QUERY_LIMIT)
                {
                    Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit.");
                }
                Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status);
                Assert.AreEqual("1,2", result.OriginAddresses.First());
            }
            finally
            {
                GoogleMaps.DistanceMatrix.OnUriCreated -= onUriCreated;
            }
        }
Exemple #24
0
        private Tuple <double?, long> GetDistanceBetweenTwoAddresses(Address addressOrigin, Address addressDestination)
        {
            DistanceMatrixRequest request = new DistanceMatrixRequest();

            GetLatirudeAndLogitudeOfAnAddress(addressOrigin);
            GetLatirudeAndLogitudeOfAnAddress(addressDestination);

            request.AddDestination(new LatLng(latitude: (decimal)addressOrigin.Latitude.Value, longitude: (decimal)addressOrigin.Longitude));

            request.AddOrigin(new LatLng(latitude: (decimal)addressDestination.Latitude.Value, longitude: (decimal)addressDestination.Longitude));

            request.Mode  = TravelMode.driving;
            request.Units = Units.metric;

            DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request);

            long   duration = 0;
            double?distance = null;

            if (response.Status == ServiceResponseStatus.Ok && response.Rows.Length == 1)
            {
                duration = response.Rows[0].Elements[0].duration.Value;
                distance = response.Rows[0].Elements[0].distance.Value;
                return(Tuple.Create(distance, duration));
            }
            else if (response.Status == ServiceResponseStatus.OverQueryLimit)
            {
                Console.WriteLine("Excesso de requisições no dia!");
            }
            return(Tuple.Create(distance, duration));
        }
        public void ShouldReturnValidValueWhenTwoOriginsSpecified()
        {
            var request = new DistanceMatrixRequest
            {
                Origins      = new[] { "49.64265,12.50088", "49.17395,12.87028" },
                Destinations = new[] { "53.64308,10.52726" }
            };

            var result = GoogleMaps.DistanceMatrix.Query(request);

            if (result.Status == DistanceMatrixStatusCodes.OVER_QUERY_LIMIT)
            {
                Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit.");
            }
            Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status);
            CollectionAssert.AreEqual(
                new[] { "Alter Sirksfelder Weg 7, 23881 Koberg, Germany" },
                result.DestinationAddresses);
            CollectionAssert.AreEqual(
                new[] { "Pilsener Str. 16, 92726 Waidhaus, Germany", "Böhmerwaldstraße 19, 93444 Bad Kötzting, Germany" },
                result.OriginAddresses);
            Assert.AreEqual(2, result.Rows.Count());
            Assert.AreEqual(DistanceMatrixElementStatusCodes.OK, result.Rows.First().Elements.First().Status);
            Assert.AreEqual(DistanceMatrixElementStatusCodes.OK, result.Rows.Last().Elements.First().Status);
        }
Exemple #26
0
        public static DistanceMatrixResponse DistanceMatrix(DistanceMatrixRequest request)
        {
            if (request.WaypointsDestination.Count < 10)
            {
                DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request);
                return(response);
            }
            else
            {
                List <DistanceMatrixResponse> tempList = new List <DistanceMatrixResponse>();

                DirectionService  ds = new DirectionService();
                DirectionRequest  dr;
                DirectionResponse dre;

                DistanceMatrixRequest  _request;
                DistanceMatrixResponse _response;

                for (int i = 0; i < request.WaypointsDestination.Count; i++)
                {
                    for (int j = 0; j < request.WaypointsDestination.Count; j++)
                    {
                        //_request = new DistanceMatrixRequest()
                        //{
                        //    WaypointsOrigin = new List<Location>() { request.WaypointsOrigin[i], request.WaypointsOrigin[j] },
                        //    WaypointsDestination = new List<Location> { request.WaypointsDestination[i], request.WaypointsDestination[j] },
                        //    Mode = TravelMode.driving,
                        //    Units = Units.metric
                        //};

                        //_response = new DistanceMatrixService().GetResponse(_request);
                        //tempList.Add(_response);

                        dr = new DirectionRequest()
                        {
                            Origin      = new Location("Kraków"),
                            Destination = new Location("Limanowa")
                        };

                        //DirectionRequest directionsRequest = new DirectionRequest()
                        //{
                        //    Origin = "Surrey, UK",
                        //    Destination = "London, UK",
                        //}

                        //DirectionResponse directionsResponse = GoogleMapsApi.GoogleMaps.Directions.Query(directionsRequest);

                        dre = ds.GetResponse(dr);
                    }
                }

                //var temp = ds.GetResponse(DirectionRequest request);
                //ds.GetResponse
            }
            //DistanceMatrixRequest request;



            return(null);
        }
Exemple #27
0
        public void DistanceMatrixTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key          = this.ApiKey,
                Origins      = new[] { new Location(40.7141289, -73.9614074) },
                Destinations = new[] { new Location("185 Broadway Ave, Manhattan, NY, USA") }
            };
            var response = GoogleMaps.DistanceMatrix.Query(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(Status.Ok, response.Status);
            Assert.IsNotNull(response.OriginAddresses.FirstOrDefault());
            Assert.IsNotNull(response.DestinationAddresses.FirstOrDefault());

            var row = response.Rows.FirstOrDefault();

            Assert.IsNotNull(row);

            var element = row.Elements.FirstOrDefault();

            Assert.IsNotNull(element);
            Assert.AreEqual(Status.Ok, element.Status);
            Assert.IsNotNull(element.Distance.Text);
            Assert.AreEqual(8258.00, element.Distance.Value, 1000.00);
            Assert.IsNotNull(element.Duration.Text);
            Assert.AreEqual(1135.00, element.Duration.Value, 200.00);
        }
Exemple #28
0
        public async Task <double> CalculateDistance(string origin, string destination)
        {
            DistanceMatrixRequest req = new DistanceMatrixRequest()
            {
                BingMapsKey = _bingApiKey,
                Origins     = new List <SimpleWaypoint>()
                {
                    new SimpleWaypoint(origin)
                },
                Destinations = new List <SimpleWaypoint>()
                {
                    new SimpleWaypoint(destination)
                },
                DistanceUnits = DistanceUnitType.Kilometers,
                TravelMode    = TravelModeType.Driving
            };

            Response response = await req.Execute();

            Resource           resource = response.ResourceSets[0].Resources[0];
            DistanceMatrix     matrix   = resource as DistanceMatrix;
            DistanceMatrixCell cell     = matrix.Results[0];

            return(cell.TravelDistance);
        }
Exemple #29
0
        public async Task <DistanceResponse> GetDistanceAsync(DistanceRequest request)
        {
            var distanceRequest = new DistanceMatrixRequest
            {
                Origins = new[]
                {
                    new Location(request.Origin.Latitude, request.Origin.Longitude)
                },
                Destinations = new[]
                {
                    new Location(request.Destination.Latitude, request.Destination.Longitude)
                },
                TravelMode = TravelMode.Driving,
                Language   = Language.Ukrainian,
                Units      = Units.Metric,
                Key        = ServicesConstants.GOOGLE_MAPS_API_KEY
            };

            var distanceResponse = await GoogleMaps.DistanceMatrix.QueryAsync(distanceRequest);

            if (distanceResponse?.Status != Status.Ok)
            {
                return(null);
            }

            var data = distanceResponse.Rows?.First()?.Elements?.First();

            var response = new DistanceResponse
            {
                Duration = data?.Duration?.Value,
                Distance = Math.Round(data.Distance.Value / MetresInKilometer, RoundingDigits)
            };

            return(response);
        }
        public void GetQueryStringParametersWhenUnitsTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key     = "key",
                Origins = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Destinations = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Units = Units.Imperial
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var units         = queryStringParameters.FirstOrDefault(x => x.Key == "units");
            var unitsExpected = request.Units.ToString().ToLower();

            Assert.IsNotNull(units);
            Assert.AreEqual(unitsExpected, units.Value);
        }