public void DrivingDistancebyAddress() { DistanceMatrixRequest request = new DistanceMatrixRequest(); //sheffield request.AddDestination(new Location("Sheffield")); //rotherham request.AddOrigin(new Location("Rotherham")); request.Sensor = true; request.Mode = TravelMode.driving; DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request); Assert.IsTrue(response.Status == ServiceResponseStatus.Ok); }
public void DrivingDistancebyAddressAndLngLat() { DistanceMatrixRequest request = new DistanceMatrixRequest(); //sheffield request.AddDestination(new Location("Sheffield")); //rotherham request.AddOrigin(new LatLng(latitude: 53.434297m, longitude: -1.364678m)); request.Sensor = true; request.Mode = TravelMode.driving; DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request); Assert.IsTrue(response.Status == ServiceResponseStatus.Ok); }
public void DrivingDistancebyAddress() { DistanceMatrixRequest request = new DistanceMatrixRequest(); //sheffield request.AddDestination(new Location("Sheffield")); //rotherham request.AddOrigin(new Location("Rotherham")); request.Mode = TravelMode.driving; DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request); Assert.AreEqual(ServiceResponseStatus.Ok, response.Status); }
public void DrivingDistancebyAddressAndLngLat() { DistanceMatrixRequest request = new DistanceMatrixRequest(); //sheffield request.AddDestination(new Location("Sheffield")); //rotherham request.AddOrigin(new LatLng(latitude: 53.434297m, longitude: -1.364678m)); request.Mode = TravelMode.driving; DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request); Assert.AreEqual(ServiceResponseStatus.Ok, response.Status); }
private void Calculate() { var req = new DistanceMatrixRequest(); req.AddOrigin(new Waypoint() { Address = _start.ToString() }); req.AddDestination(new Waypoint() {Address = _stop.ToString()}); req.Sensor = false; req.Mode = TravelMode.driving; req.Units = Units.imperial; var response = new DistanceMatrixService().GetResponse(req); Distance = Convert.ToInt32(response.Rows.First().Elements.First().distance.Value); Duration = Convert.ToInt32(response.Rows.First().Elements.First().duration.Value); Console.WriteLine("Distance from {0}, to {1} is {2} - Travel Time: {3}", _start, _stop, Distance, Duration); }
public void DrivingDistancebyLngLatHasOneOriginAndDestinationAdresses() { DistanceMatrixRequest request = new DistanceMatrixRequest(); //rotherham request.AddOrigin(new LatLng(latitude: 53.434297m, longitude: -1.364678m)); //sheffield request.AddDestination(new LatLng(latitude: 53.378243m, longitude: -1.462131m)); request.Mode = TravelMode.driving; DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request); Assert.AreEqual(ServiceResponseStatus.Ok, response.Status); Assert.AreEqual(1, response.DestinationAddresses.Length); Assert.AreEqual(1, response.OriginAddresses.Length); }
public void DrivingDistancebyAddressHasOneOriginAndMultipleDestinationAdresses() { DistanceMatrixRequest request = new DistanceMatrixRequest(); //rotherham request.AddOrigin(new Location("Rotherham")); //sheffield request.AddDestination(new Location("Sheffield")); request.AddDestination(new Location("London")); request.Mode = TravelMode.driving; DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request); Assert.AreEqual(ServiceResponseStatus.Ok, response.Status); Assert.Greater(response.DestinationAddresses.Length, 1); Assert.AreEqual(1, response.OriginAddresses.Length, 1); }
public void DrivingDistancebyLngLatHasOneOriginAndMultipleDestinationAdresses() { DistanceMatrixRequest request = new DistanceMatrixRequest(); //rotherham request.AddOrigin(new LatLng(latitude: 53.434297m, longitude: -1.364678m)); //sheffield request.AddDestination(new LatLng(latitude: 53.378243m, longitude: -1.462131m)); request.AddDestination(new LatLng(latitude: 51.378243m, longitude: -1.162131m)); request.Sensor = true; request.Mode = TravelMode.driving; DistanceMatrixResponse response = new DistanceMatrixService().GetResponse(request); Assert.IsTrue(response.Status == ServiceResponseStatus.Ok); Assert.IsTrue(response.DestinationAddresses.Length > 1); Assert.IsTrue(response.OriginAddresses.Length == 1); }
DistanceMatrixService CreateService() { var svc = new DistanceMatrixService(TestingApiKey); return(svc); }
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 Distancia BuscarMenorDistancia(Endereco origem, IEnumerable<Endereco> destinos) { var distanceMatrixRequest = new DistanceMatrixRequest() { Units = Units.metric, Mode = TravelMode.walking, Language = "pt", Sensor = false }; #pragma warning disable 0618 distanceMatrixRequest.AddOrigin(new Waypoint((decimal)origem.Coordenadas.Latitude, (decimal)origem.Coordenadas.Longitude)); var waypointDestinos = destinos.Select( destino => new Waypoint( (decimal)destino.Coordenadas.Latitude, (decimal)destino.Coordenadas.Longitude)); #pragma warning restore 0618 foreach (var waypoint in waypointDestinos) distanceMatrixRequest.AddDestination(waypoint); var distanceMatrixResponse = new DistanceMatrixService().GetResponse(distanceMatrixRequest); if (distanceMatrixResponse.Status != ServiceResponseStatus.Ok) throw new Exception(); var distancias = distanceMatrixResponse.Rows[0].Elements. Zip(destinos, (matrix, destino) => new Distancia(origem, destino, int.Parse(matrix.distance.Value))); return distancias.OrderBy(x => x.Valor).First(); }