Ejemplo n.º 1
0
 Rota IRota.EvitandoTransito(Endereco end1, Endereco end2)
 {
     return this.CalculaRota(end1, end2, EnumTipoRota.EvitarPedagio);
 }
Ejemplo n.º 2
0
 Rota IRota.MaisRapida(Endereco end1, Endereco end2)
 {
     return this.CalculaRota(end1, end2, EnumTipoRota.MaisRapido);
 }
Ejemplo n.º 3
0
        private Rota CalculaRota(Endereco end1, Endereco end2, EnumTipoRota tipoRota)
        {
            var address1 = new Address
            {
                street = end1.NomeRuaAvenida,
                houseNumber = end1.Numero.ToString(),
                city = new ServiceAddressFinder.City { name = end1.Cidade, state = end1.Estado }
            };

            var address2 = new Address
            {
                street = end2.NomeRuaAvenida,
                houseNumber = end2.Numero.ToString(),
                city = new ServiceAddressFinder.City { name = end2.Cidade, state = end2.Estado }
            };

            var afSoa = new AddressFinderSoapClient();
            afSoa.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://services.maplink.com.br/webservices/v3/AddressFinder/AddressFinder.asmx");
            var addressXY1 = afSoa.getXY(address1, token);
            var addressXY2 = afSoa.getXY(address2, token);

            var rSoa = new RouteSoapClient();
            var routes = new[] {
                new RouteStop
                {
                    description = address1.street+ ", "+address1.houseNumber,
                    point = new ServiceRoute.Point { x = addressXY1.x, y = addressXY1.y }
                },
                new RouteStop
                {
                    description = address2.street+ ", "+address2.houseNumber,
                    point = new ServiceRoute.Point { x = addressXY2.x, y = addressXY2.y }
                }
            };
            var routeOptions = new RouteOptions
            {
                language = "portugues",
                routeDetails = new RouteDetails { descriptionType = 0, routeType = (int)tipoRota, optimizeRoute = true },
                vehicle = new Vehicle
                {
                    tankCapacity = 20,
                    averageConsumption = 9,
                    fuelPrice = 3,
                    averageSpeed = 60,
                    tollFeeCat = 2
                }
            };
            var getRouteResponse = rSoa.getRoute(routes, routeOptions, token);
            var rt = getRouteResponse.routeTotals;

            this.CustoCombustivel = rt.totalfuelCost;
            this.CustoComPedagio = this.CustoCombustivel + rt.totaltollFeeCost;
            this.DistanciaTotal = rt.totalDistance;
            this.TotalTempo = rt.totalTime;

            return this;
        }