Ejemplo n.º 1
0
        public void DesenharRota(JObject rotaEscolhida)
        {
            foreach (Polyline linha in this.PolylinesCaminhoParaVaga)
            {
                try
                {
                    linha.Remove();
                }
                catch { }
            }


            RotaAtual = rotaEscolhida;
            string polylineString = (rotaEscolhida["overview_polyline"])["points"].ToString();

            var             polyline = GooglePoints.Decode(polylineString);
            PolylineOptions opt      = new PolylineOptions();

            foreach (var point in polyline)
            {
                opt = opt.Add(point);
            }
            ;
            opt = opt.InvokeWidth(20);
            opt = opt.InvokeColor(this.CorLinhaEstrada);

            this.PolylinesCaminhoParaVaga.Add(Mapa.AddPolyline(opt));
        }
Ejemplo n.º 2
0
        private void MostrarRotaParaVaga(Vaga vaga)
        {
            this.ControleMapa.PolylinesCaminhoParaVaga.ForEach(x => x.Remove());

            JObject estacionamento = null;

            if (ControleMapa.EstacionamentoSelecionado != null && ControleMapa.EstacionamentoSelecionado.Value <long>("Id") == vaga.IdEstacionamento)
            {
                estacionamento = ControleMapa.EstacionamentoSelecionado;
            }
            else
            {
                try
                {
                    estacionamento = ControleMapa.ObterEstacionamento(vaga.IdEstacionamento);
                }
                catch (Exception ex) {
                    return;
                }
            }
            if (estacionamento == null)
            {
                return;
            }

            JArray pontos = (JArray)estacionamento["Pontos"];

            Graph g = new Graph();

            /*
             * g.add_vertex('A', new Dictionary<char, int>() { { 'B', 7 }, { 'C', 8 } });
             * g.add_vertex('B', new Dictionary<char, int>() { { 'A', 7 }, { 'F', 2 } });
             * g.add_vertex('C', new Dictionary<char, int>() { { 'A', 8 }, { 'F', 6 }, { 'G', 4 } });
             * g.add_vertex('D', new Dictionary<char, int>() { { 'F', 8 } });
             * g.add_vertex('E', new Dictionary<char, int>() { { 'H', 1 } });
             * g.add_vertex('F', new Dictionary<char, int>() { { 'B', 2 }, { 'C', 6 }, { 'D', 8 }, { 'G', 9 }, { 'H', 3 } });
             * g.add_vertex('G', new Dictionary<char, int>() { { 'C', 4 }, { 'F', 9 } });
             * g.add_vertex('H', new Dictionary<char, int>() { { 'E', 1 }, { 'F', 3 } });
             */
            JObject entrada = (JObject)pontos.Where(x => x.Value <bool>("Entrada") == true).FirstOrDefault();

            foreach (JObject ponto in pontos)
            {
                // g.add_vertex('A', new Dictionary<long, int>() { { 'B', 7 }, { 'C', 8 } });
                long id = ponto.Value <long>("Id");
                Dictionary <string, int> distancias = new Dictionary <string, int>();
                LatLng origem = new LatLng(ponto["Localizacao"].Value <double>("Latitude"), ponto["Localizacao"].Value <double>("Longitude"));
                foreach (var conexao in ponto["ConexoesComplexas"])
                {
                    var    alvo    = pontos.Where(x => x.Value <long>("Id") == conexao.ToObject <long>()).FirstOrDefault();
                    LatLng destino = new LatLng(alvo["Localizacao"].Value <double>("Latitude"), alvo["Localizacao"].Value <double>("Longitude"));

                    var distancia = (int)(CalculationByDistance(origem, destino) * 1000);
                    distancias.Add(alvo.Value <long>("Id").ToString(), distancia);
                }

                g.add_vertex(ponto.Value <long>("Id").ToString(), distancias);
            }
            string c_entrada = entrada.Value <long>("Id").ToString();
            string c_alvo    = vaga.Ponto.Value <long>("Id").ToString();


            var shortPath = g.shortest_path(c_entrada, c_alvo);

            JArray        caminho = new JArray();
            List <string> demo    = new List <string>();

            foreach (var no in shortPath)
            {
                var ponto = pontos.Where(x => no == x.Value <long>("Id").ToString()).FirstOrDefault();
                demo.Add(no);
                caminho.Add(ponto);
            }

            PolylineOptions opt  = new PolylineOptions();
            double          _lat = entrada["Localizacao"].Value <double>("Latitude");
            double          _lng = entrada["Localizacao"].Value <double>("Longitude");



            opt = opt.InvokeWidth(20);
            opt = opt.InvokeColor(Color.DarkSlateBlue);

            opt.Add(vaga.Marker.Position);
            foreach (var no in caminho)
            {
                double lat = no["Localizacao"].Value <double>("Latitude");
                double lng = no["Localizacao"].Value <double>("Longitude");
                opt = opt.Add(new LatLng(lat, lng));
            }
            opt.Add(new LatLng(_lat, _lng));



            if (ControleMapa.LocalizacaoAtual == null)
            {
                if (!alertadoGpsDesligado)
                {
                    AlertaServicoLocalizacao();
                    alertadoGpsDesligado = true;
                }
            }
            else
            {
                string  origem_s  = ControleMapa.LocalizacaoAtual.Latitude.ToString("0.000000", System.Globalization.CultureInfo.InvariantCulture) + "," + ControleMapa.LocalizacaoAtual.Longitude.ToString("0.000000", System.Globalization.CultureInfo.InvariantCulture);
                string  destino_s = estacionamento["Localizacao"].Value <double>("Latitude").ToString("0.000000", System.Globalization.CultureInfo.InvariantCulture) + "," + estacionamento["Localizacao"].Value <double>("Longitude").ToString("0.000000", System.Globalization.CultureInfo.InvariantCulture);
                JObject direcoes  = ControleMapa.ObterDirecoes(origem_s, destino_s, false);


                string polylineString = ((JObject)(direcoes["routes"]).First["overview_polyline"])["points"].ToString();

                var polyline = GooglePoints.Decode(polylineString);
                for (int i = polyline.Count() - 1; i >= 0; i--)
                {
                    opt = opt.Add(polyline.ElementAt(i));
                }
            }
            ControleMapa.PolylinesCaminhoParaVaga.Add(GMap.AddPolyline(opt));
        }