public async Task <Route> CalcuteRouteAsync(IList <AddressSearch> addressSearches, RouteType routeType) { var routeStops = new List <RouteStop>(); addressSearches.ToList().ForEach(x => { var routeStop = Mapper.Map <AddressSearch, RouteStop>(x); var point = Mapper.Map <AddressSearch, Point>(x); routeStop.point = point; routeStops.Add(routeStop); }); var options = _config.GetRouteOptions(routeType); using (var routeSoapClient = new RouteSoapClient()) { var response = await routeSoapClient.getRouteAsync(routeStops.ToArray(), options, _token.Tokenvalue); if (response.Body.getRouteResult.routeTotals != null) { var route = Mapper.Map <RouteTotals, Route>(response.Body.getRouteResult.routeTotals); return(route); } } return(null); }
public async Task<Route> CalcuteRouteAsync(IList<AddressSearch> addressSearches, RouteType routeType) { var routeStops = new List<RouteStop>(); addressSearches.ToList().ForEach(x => { var routeStop = Mapper.Map<AddressSearch, RouteStop>(x); var point = Mapper.Map<AddressSearch, Point>(x); routeStop.point = point; routeStops.Add(routeStop); }); var options = _config.GetRouteOptions(routeType); using (var routeSoapClient = new RouteSoapClient()) { var response = await routeSoapClient.getRouteAsync(routeStops.ToArray(), options, _token.Tokenvalue); if (response.Body.getRouteResult.routeTotals != null) { var route = Mapper.Map<RouteTotals, Route>(response.Body.getRouteResult.routeTotals); return route; } } return null; }
public RouteTotals GetRouteTotalsResponse(IList<RouteStop> routes, RouteOptions routeOptions) { using (var routeSoapClient = new RouteSoapClient()) { return routeSoapClient.getRouteTotals((List<RouteStop>) routes, routeOptions, Configuration.TokenValue); } }
public RouteTotals GetRouteTotalsResponse(IList <RouteStop> routes, RouteOptions routeOptions) { using (var routeSoapClient = new RouteSoapClient()) { return(routeSoapClient.getRouteTotals((List <RouteStop>)routes, routeOptions, Configuration.TokenValue)); } }
public JsonResult GetInfoMapLink(MapLinkConsulta dados) { try { const string token = "c13iyCvmcC9mzwkLd0LCbmYC5mUF5m2jNGNtNGt6NmK6NJK="; var originRoute = new RouteStop { description = "", point = new Point { x = Convert.ToDouble(dados.origem.longitude,cult) , y = Convert.ToDouble(dados.origem.latitude, cult) } }; var destinationRoute = new RouteStop { description = "", point = new Point { x = Convert.ToDouble(dados.destino.longitude,cult), y = Convert.ToDouble(dados.destino.latitude,cult) } }; var routes = new[] { originRoute, destinationRoute }; var routeOptions = new RouteOptions { language = "portugues", routeDetails = new RouteDetails { descriptionType = 0, routeType = 1, optimizeRoute = true }, vehicle = new Vehicle { tankCapacity = 20, averageConsumption = 9, fuelPrice = 3, averageSpeed = 60, tollFeeCat = 2 } }; using (var routeSoapClient = new RouteSoapClient()) { var getRouteTotalsResponse = routeSoapClient.getRouteTotals(routes, routeOptions, token); var resultado = new { consumo = getRouteTotalsResponse.totalFuelUsed.ToString(cult), distancia = getRouteTotalsResponse.totalDistance.ToString(cult), tempototal = getRouteTotalsResponse.totalTime.ToString(cult) }; return Json(resultado, JsonRequestBehavior.AllowGet); } return null; } catch (Exception ex) { return null; } }
public RouteTotals Calculate(RouteStop[] routes, int routeType) { this.ErrorMessage = String.Empty; try { using (var routeSoapClient = new RouteSoapClient()) { var getRouteTotalsResponse = routeSoapClient .getRouteTotals(routes, this.DefaultRouteOptions(routeType), this.Token); return getRouteTotalsResponse; } } catch (System.ServiceModel.FaultException e) { this.ErrorMessage = e.Message; return null; } }
private RouteCost RequestRouteCost(RouteType routeType) { _routeDetails = new RouteDetails(); _routeDetails.descriptionType = Config.DesciptionType; _routeDetails.optimizeRoute = true; _routeDetails.routeType = Convert.ToInt32(routeType); _routeOptions.routeDetails = _routeDetails; using (var routeSoapClient = new RouteSoapClient()) { _routeInfo = routeSoapClient.getRoute(GenerateRouteStop(), _routeOptions, _token); } return(new RouteCost { TotalDistance = _routeInfo.routeTotals.totalDistance, TotalFuelCost = _routeInfo.routeTotals.totalfuelCost, TotalCostWithToll = _routeInfo.routeTotals.totalCost, TotalTimeRote = _routeInfo.routeTotals.totalTime }); }
/// <summary> /// Método para retorno de informações e valores sobre a rota /// </summary> /// <param name="token">Chave para autenticação</param> /// <param name="enderecoPartida">Endereco com número de partida, ex: Av Paulista, 1000</param> /// <param name="cidadeUfPartida">Cidade e estado de partida, ex: São Paulo,SP</param> /// <param name="enderecoDestino">Endereco com número de destino, ex: Av Paulista, 1000</param> /// <param name="cidadeUfDestino">Cidade e estado de destino, ex: São Paulo,SP</param> /// <param name="veiculo">Infomar: CapacidadeTanque,ConsumoMedio,ValorCombustivel,VelocidadeMedia,CategoriaVeiculo(1-Moto,2-Carro,5-Onibus,7-Caminhao)</param> /// <param name="tipoRota">0 = Rota padrão mais rápida, 1 = Rota evitando o trânsito. (Somente utilizando base urbana)</param> /// <returns>Tempo total da rota;Distância total;Custo de combustível;Custo total considerando pedágio</returns> public ResponseInformacoesRota GetInformacoesRota(string token, string enderecoPartida, string cidadeUfPartida, string enderecoDestino, string cidadeUfDestino, Veiculo veiculo, int tipoRota = 0) { try { if (string.IsNullOrEmpty(enderecoPartida) || enderecoPartida.Split(',').Length != 2) { return new ResponseInformacoesRota { Exception = "O endereço de partida deve ser preenchido corretamente: ex: Av Paulista, 1000" } } ; if (string.IsNullOrEmpty(cidadeUfPartida) || cidadeUfPartida.Split(',').Length != 2) { return new ResponseInformacoesRota { Exception = "A cidade e UF de partida deve ser preenchida corretamente, ex: São Paulo, SP" } } ; if (string.IsNullOrEmpty(enderecoDestino) || enderecoDestino.Split(',').Length != 2) { return new ResponseInformacoesRota { Exception = "O endereço de destino deve ser preenchido corretamente: ex: Av Paulista, 2000" } } ; if (string.IsNullOrEmpty(cidadeUfDestino) || cidadeUfDestino.Split(',').Length != 2) { return new ResponseInformacoesRota { Exception = "A cidade de destino deve ser preenchida corretamente, ex: São Paulo, SP" } } ; if (veiculo == null) { return new ResponseInformacoesRota { Exception = "As informações do veículo devem ser preenchidas" } } ; if (veiculo.CapacidadeTanque <= 0) { return new ResponseInformacoesRota { Exception = "A capacidade do tanque deve ser informada" } } ; if (veiculo.CategoriaVeiculo <= 0) { return new ResponseInformacoesRota { Exception = "A categoria do veículo deve ser informada" } } ; if (veiculo.ConsumoMedio <= 0) { return new ResponseInformacoesRota { Exception = "O consumo médio do veículo deve ser informado" } } ; if (veiculo.ValorCombustivel <= 0) { return new ResponseInformacoesRota { Exception = "O valor do combustível deve ser informado" } } ; //ToDo: Verificar se existe método no webservice que calcula velocidade média da viagem if (veiculo.VelocidadeMedia <= 0) { return new ResponseInformacoesRota { Exception = "A velocidade média a ser empregada na viagem deve ser informada" } } ; var addressStart = new Address { street = enderecoPartida.Split(',')[0].Trim(), houseNumber = enderecoPartida.Split(',')[1].Trim(), city = new ServiceAddress.City { name = cidadeUfPartida.Split(',')[0].Trim(), state = cidadeUfPartida.Split(',')[1].Trim() } }; var addressEnd = new Address { street = enderecoDestino.Split(',')[0].Trim(), houseNumber = enderecoDestino.Split(',')[1].Trim(), city = new ServiceAddress.City { name = cidadeUfDestino.Split(',')[0].Trim(), state = cidadeUfDestino.Split(',')[1].Trim() } }; var addressOptions = new AddressOptions { usePhonetic = true, searchType = 2, resultRange = new ResultRange { pageIndex = 1, recordsPerPage = 1 } }; double xPartida = 0; double yPartida = 0; using (var addressFinderSoapClient = new AddressFinderSoapClient()) { var findAddressResponse = addressFinderSoapClient.findAddress(addressStart, addressOptions, token); if (findAddressResponse.addressLocation.Count() == 0) { return new ResponseInformacoesRota { Exception = "O endereço de partida não foi localizado, verifique" } } ; xPartida = findAddressResponse.addressLocation.First().point.x; yPartida = findAddressResponse.addressLocation.First().point.y; } double xDestino = 0; double yDestino = 0; using (var addressFinderSoapClient = new AddressFinderSoapClient()) { var findAddressResponse = addressFinderSoapClient.findAddress(addressEnd, addressOptions, token); if (findAddressResponse.addressLocation.Count() == 0) { return new ResponseInformacoesRota { Exception = "O endereço de chegada não foi localizado, verifique" } } ; xDestino = findAddressResponse.addressLocation.First().point.x; yDestino = findAddressResponse.addressLocation.First().point.y; } var originRoute = new ServiceRouteMapLink.RouteStop { description = addressStart.street, point = new ServiceRouteMapLink.Point { x = xPartida, y = yPartida } }; var destinationRoute = new ServiceRouteMapLink.RouteStop { description = addressEnd.street, point = new ServiceRouteMapLink.Point { x = xDestino, y = yDestino } }; var routes = new[] { originRoute, destinationRoute }; var opcaoRota = DescriptionType.RotaUrbana; tipoRota = (int)RouteType.PadraoRapida; //Se a cidade for diferente troca o descriptionType para rota rodoviária if (!cidadeUfPartida.Trim().Equals(cidadeUfDestino.Trim())) { opcaoRota = DescriptionType.RotaRodoviaria; } var routeOptions = new RouteOptions { language = "portugues", routeDetails = new RouteDetails { descriptionType = (int)opcaoRota, routeType = tipoRota, optimizeRoute = true }, vehicle = new Vehicle { tankCapacity = veiculo.CapacidadeTanque, averageConsumption = veiculo.ConsumoMedio, fuelPrice = veiculo.ValorCombustivel, averageSpeed = veiculo.VelocidadeMedia, tollFeeCat = veiculo.CategoriaVeiculo } }; using (var routeSoapClient = new RouteSoapClient()) { var getRouteResponse = routeSoapClient.getRoute(routes, routeOptions, token); var result = new ResponseInformacoesRota { TempoTotal = getRouteResponse.routeTotals.totalTime, DistanciaTotal = getRouteResponse.routeTotals.totalDistance, CustoCombustivel = getRouteResponse.routeTotals.totalfuelCost, CustoPedagioCombustivel = getRouteResponse.routeTotals.totalCost }; return(result); } } catch (Exception) { return(new ResponseInformacoesRota { Exception = "Não foi possível processar sua solicitação" }); } }
private RouteCost RequestRouteCost(RouteType routeType) { _routeDetails = new RouteDetails(); _routeDetails.descriptionType = Config.DesciptionType; _routeDetails.optimizeRoute = true; _routeDetails.routeType = Convert.ToInt32(routeType); _routeOptions.routeDetails = _routeDetails; using (var routeSoapClient = new RouteSoapClient()) { _routeInfo = routeSoapClient.getRoute(GenerateRouteStop(), _routeOptions, _token); } return new RouteCost { TotalDistance = _routeInfo.routeTotals.totalDistance, TotalFuelCost = _routeInfo.routeTotals.totalfuelCost, TotalCostWithToll = _routeInfo.routeTotals.totalCost, TotalTimeRote = _routeInfo.routeTotals.totalTime }; }
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; }
public ActionResult Index(HttpPostedFileBase file) { MapLinkArquivoOutput resultado = new MapLinkArquivoOutput(); // Verify that the user selected a file if (file != null && file.ContentLength > 0) { resultado.itens = new List<MapLinkOutputItem>(); StreamReader stream = new StreamReader(file.InputStream); string conteudo = stream.ReadToEnd(); List<MapLinkFileInput> input = DecodeMapLinkInputFile(conteudo); const string token = "c13iyCvmcC9mzwkLd0LCbmYC5mUF5m2jNGNtNGt6NmK6NJK="; foreach(var item in input){ var originRoute = new RouteStop { description = "", point = new Point { x = Convert.ToDouble(item.originCoordinate.longitude,cult) , y = Convert.ToDouble(item.originCoordinate.latitude, cult) } }; var destinationRoute = new RouteStop { description = "", point = new Point { x = Convert.ToDouble(item.destinationCoordinate.longitude,cult), y = Convert.ToDouble(item.destinationCoordinate.latitude,cult) } }; var routes = new[] { originRoute, destinationRoute }; var routeOptions = new RouteOptions { language = "portugues", routeDetails = new RouteDetails { descriptionType = 0, routeType = 1, optimizeRoute = true }, vehicle = new Vehicle { tankCapacity = 20, averageConsumption = 9, fuelPrice = 3, averageSpeed = 60, tollFeeCat = 2 } }; using (var routeSoapClient = new RouteSoapClient()) { var getRouteTotalsResponse = routeSoapClient.getRouteTotals(routes, routeOptions, token); resultado.itens.Add(new MapLinkOutputItem(){ id=item.id, consumo=getRouteTotalsResponse.totalFuelUsed.ToString(cult), distancia=getRouteTotalsResponse.totalDistance.ToString(cult), tempototal=getRouteTotalsResponse.totalTime.ToString(cult) }); } } } // redirect back to the index action to show the form once again return View("Index",resultado); }