Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] Busca de proximidades - Postgis

Olá Jeordane,

Você pode usar esse método aqui para saber a distancia de um ponto ao outro....ai e só melhorar e adaptar a sua necessidade.

public static String GetDistance(LatLng src, LatLng dest) throws IOException {
        
        /*
         * URL original
         * 
         * 
         */
         
 
        StringBuilder urlString = new StringBuilder();
        urlString.append("origins=");//from
        urlString.append(src.latitude);
        urlString.append(",");
        urlString.append(src.longitude);
        urlString.append("&destinations=");//to
        urlString.append(dest.latitude);
        urlString.append(",");
        urlString.append(dest.longitude);
        urlString.append("&mode=driving&language=pt-BR&sensor=true");
         
 
        HttpURLConnection urlConnection= null;
        URL url = null;
 
        url = new URL(urlString.toString());
        urlConnection=(HttpURLConnection)url.openConnection();
        urlConnection.setRequestMethod("GET");
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);
        urlConnection.connect();
 
        InputStream inStream = urlConnection.getInputStream();
        BufferedReader bReader = new BufferedReader(new InputStreamReader(inStream));
 
        String temp, response = "";
        while((temp = bReader.readLine()) != null){
            //Parse data
            response += temp;
        }
        //Close the reader, stream & connection
        bReader.close();
        inStream.close();
        urlConnection.disconnect();
 
        //Sortout JSONresponse 
        JSONObject object;
        try {
            object = (JSONObject) new JSONTokener(response).nextValue();
            JSONArray array = object.getJSONArray("rows");
            JSONObject routes = array.getJSONObject(0);
            JSONArray legs = routes.getJSONArray("elements");
 
            JSONObject duration = legs.getJSONObject(0);
            JSONObject distance = duration.getJSONObject("distance");
            String sDuration = distance.getString("text");
         
            return sDuration;
         
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
         
         
        
 
    }

Diogo Henrique
(83)87344178
Rede Sociais: 






Em 14 de julho de 2014 20:21, Jeordane Batista <jeordane10@gmail.com> escreveu:



Tenho registros armazenados em uma tabela com a latitude / longitude armazenadas em um campo de geometria. Eu quero encontrar todos os registros nas proximidades de um usuário fornecido ponto de referência. Nota "nas proximidades" provavelmente significa menos de 100 quilômetros (possivelmente ainda menor).

A tabela é composta pelas seguintes informações

Tabela: estabelecimento

  id type = serial|nome type = varchar(80)|localizacao = type point|  01              |Estabelecimento 01     |(-20.02269481,-45.54468155)  02              |Estabelecimento 02     |(-20.020777,-45.54372)  03              |Estabelecimento 03     |(-20.039084,-45.528041)  ...
selecionar os estabelecimentos que esteja em um raio de até 1km (por exemplo), de um determinado Ponto. 


Vale lembrar que estou utilizando base de dados PostGIS


Alguém que possa me ajudar? Obrigado


--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário