我正在与位置管理器一起在我的应用程序中实现相同的功能,我想在一个人的实际位置周围显示咖啡店。根据电话显示的内容,我可以对经纬度进行反向地理编码,并在数组列表中获取位置。现在,我对结果集中的“位置”字段感兴趣。有什么建议我该怎么做?下面是我的代码。

    if(gps.canGetLocation()){

                     latitude = gps.getLatitude();
                     longitude = gps.getLongitude();
                     Geocoder myLocation = new Geocoder(getApplicationContext(), Locale.getDefault());
                     try {
                        List<Address> myList = myLocation.getFromLocation(latitude, longitude, 1);

                        Toast.makeText(getApplicationContext(), ""+myList, Toast.LENGTH_LONG).show();
                         Iterator<Address> it = myList.iterator();

                            while (it.hasNext()) {

                                TextView tv = (TextView)findViewById(R.id.tv);
                                tv.setText("Data is"+it.next());


                            }

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

最佳答案

我找到了!它去了:

   if (myList != null && myList.size() > 0) {
    Address address = myList.get(0);
    String result = address.getLocality();
    Toast.makeText(getApplicationContext(), ""+result, Toast.LENGTH_LONG).show();
                        }

10-07 19:04
查看更多