예제 #1
0
        public static GeographicPosition BuscarCoordenadas(string cep, string endereco, string cidade, string estado)
        {
            try
            {
                bool achouCEP  = false;
                var  estrutura = new EstruturaCEP();

                if (!string.IsNullOrEmpty(cep))
                {
                    try
                    {
                        estrutura = BuscarCEP.GetEnderecoEstruturado(cep);
                        achouCEP  = true;
                    }
                    catch (Exception)
                    { }
                }

                if (!achouCEP)
                {
                    if (endereco.Contains("-"))
                    {
                        string[] enderecos = endereco.Split('-');
                        estrutura.Rua = enderecos[0];
                    }
                    else
                    {
                        estrutura.Rua    = endereco;
                        estrutura.Cidade = cidade;
                        estrutura.Estado = estado;
                    }
                }

                var request = new GeocodingRequest();
                request.Address = FormatarEstrutra(estrutura);
                request.Sensor  = "false";
                var response = GeocodingService.GetResponse(request);

                if (response.Status != Google.Api.Maps.Service.ServiceResponseStatus.Ok)
                {
                    throw new Exception("Não foi possível encontrar a sua localização a partir do CEP digitado.");
                }

                return(response.Results[0].Geometry.Location);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #2
0
        public static GeographicPosition BuscarCoordenadas(string cep)
        {
            var estrutura = BuscarCEP.GetEnderecoEstruturado(cep);

            var request = new GeocodingRequest();

            request.Address = FormatarEstrutra(estrutura);
            request.Sensor  = "false";
            var response = GeocodingService.GetResponse(request);

            if (response.Status != Google.Api.Maps.Service.ServiceResponseStatus.Ok)
            {
                throw new Exception("Não foi possível encontrar a sua localização a partir do CEP digitado.");
            }

            return(response.Results[0].Geometry.Location);
        }