从反向地理编码地址中提取“位置”详细信息。

时间:2012-10-31 09:05:35

标签: java android android-location

我正在使用位置管理器在我的应用程序中实现相同的功能,我想在一个人的实际位置周围出现咖啡店。根据手机显示的内容,我可以检索纬度和经度反向地理代码,并在数组列表中获取位置。现在我对结果集中的“Locality”字段感兴趣。任何建议我如何得到它?以下是我的代码。

    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();
                    }

1 个答案:

答案 0 :(得分:1)

我找到了!在这里:

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