如何找到最近的地方例如(像医院)

时间:2015-08-31 20:52:15

标签: android location

我正在开发一个关于android中最近的地方的应用程序。但我不知道如何计算距离以及如何在列表视图中按升序排序。我该怎么用?

1 个答案:

答案 0 :(得分:1)

我使用Volley的Foursquare服务

做了这样的例子

该项目最重要的部分是:

      private void getPlaces(){
        String apiCall = "https://api.foursquare.com/v2/venues/search?client_id="+CLIENT_ID+"&client_secret="+CLIENT_SECRET+"&v=20130815%20&ll="+latitude+","+longtitude;
        JsonObjectRequest Request = new JsonObjectRequest(com.android.volley.Request.Method.GET,
                apiCall,
                (String) null,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d("Respuesta", response.toString());


                        //Parseamos la frase
                        venuesList = (ArrayList<FoursquareVenue>) parseFoursquare(response);

                        List<String> listTitle = new ArrayList<String>();

                        for (int i = 0; i < venuesList.size(); i++) {
                            listTitle.add(i, venuesList.get(i).getName() + ", " + venuesList.get(i).getCategory() + "" + venuesList.get(i).getCity());
                        }

                        // set the results to the list
                        // and show them in the xml
                        myAdapter = new ArrayAdapter<String>(MainActivity.this, R.layout.row_layout, R.id.listText, listTitle);
                        setListAdapter(myAdapter);

                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        VolleyLog.d("Respuesta", "Error: " + error.getMessage());
                        Toast.makeText(getApplicationContext(),
                                "Error: "+ error.getMessage(),
                                Toast.LENGTH_SHORT).show();
                    }
                });

        //Añadimos la solicitud a la cola de solicitudes
        AppController.getInstance().addToRequestQueue(Request);
    }

以下是整个project