コード例 #1
0
ファイル: Utils.cs プロジェクト: LeonardoADS08/IO-Path-Finder
        public static void Calcular(Grafo.Vertice V)
        {
            foreach (var val in V.Aristas)
            {
                Google.Maps.DistanceMatrix.DistanceMatrixRequest distanceRequest = new Google.Maps.DistanceMatrix.DistanceMatrixRequest()
                {
                    WaypointsOrigin = new List <Google.Maps.Location> {
                        new Google.Maps.LatLng(V.Latitud, V.Longitud)
                    },
                    WaypointsDestination = new List <Google.Maps.Location> {
                        new Google.Maps.LatLng(val.Fin.Latitud, val.Fin.Longitud)
                    },
                    Mode  = TravelMode.driving,
                    Units = Units.metric
                };

                try
                {
                    var response = new Google.Maps.DistanceMatrix.DistanceMatrixService().GetResponse(distanceRequest);
                    val.Costo  = Convert.ToDouble(response.Rows.First().Elements.First().distance.Value);
                    val.Tiempo = Convert.ToDouble(response.Rows.First().Elements.First().duration.Value);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("No fue posible hallar la distancia :c");
                    Debug.WriteLine(ex.Message);
                }
            }
        }
コード例 #2
0
        public static Grafo.Grafo SelecionarEstabelecimentoPorId(int id)
        {
            try
            {
                var d = new DynamicParameters();
                d.Add("@id", id, dbType: DbType.Int32);

                using (DataBase db = new DataBase("SqlServer"))
                {
                    Grafo.Grafo g    = new Grafo.Grafo();
                    var         tipo = db.connection.Query("spListarVerticesPorEstabelecimento", d, commandType: CommandType.StoredProcedure).AsList();
                    foreach (var item in tipo)
                    {
                        Grafo.Vertice v = new Grafo.Vertice(item.codigo);
                        v.Descricao = item.descricao;
                        v.ID        = item.id_vertice;
                        g.Vertices.Add(v);
                    }
                    return(g);
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }