本文介绍了使用地理codeR返回的选定城市的android的所有街道名称的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有被检索到的城市:

if i have a city retrieved by:

Geocoder gcd = new Geocoder(context, Locale.getDefault());
Address address = gcd.getFromLocation(lat, lng, 1);

有没有办法使用谷歌地图API来获得在选定城市的所有街道名称列表?

Is there any way to get list of all street names in a selected town using the google maps api?

更新

Geocoder gcd = new Geocoder(this, Locale.getDefault());
        List<Address> addresses = null;
        try {
            addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (addresses.size() > 0)
            for (int i = 0; i < addresses.get(0).getMaxAddressLineIndex(); i++)
                Log.e("afaf", " " + addresses.get(0).getAddressLine(i));

这将返回(例如):纽约第五街3924.And它不是在所有的城市街道迭代

this returns (for example): new york, 5th street 3924.And it doesn't iterate on all city streets.

推荐答案

我想你要找的是这样的:

I think what your looking for is this:

getFromLocationName(字符串LOCATIONNAME,诠释maxResults)

从文档:

返回已知地址来描述命名的数组  的位置,这可以是地名,例如的Dalvik,冰岛,一个  解决诸如1600剧场百汇,加州山景城,一个  机场code,如证券及期货条例,等返回的地址将是  本地化的服务提供给这个类的构造函数中的语言环境。

查询将阻止和返回的值将通过方法获得  网络查找。结果是一个最好的猜测,并不能保证  要有意义或正确的。它可能是从调用此方法有用  从主UI线程一个线程中分离出来。

The query will block and returned values will be obtained by means of a network lookup. The results are a best guess and are not guaranteed to be meaningful or correct. It may be useful to call this method from a thread separate from your primary UI thread.

要获得街道名称使用这个(我想你已经知道这一点):

to get the Street name use this(I think you already know this):

  for(int a = 0 ; a < addresses.size() ; a++){
    Address address = addresses.get(a);
    for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
       // get address like address.getAddressLine(i);
    }
  }

希望它帮助:)

hope it helps :)

这篇关于使用地理codeR返回的选定城市的android的所有街道名称的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:20
查看更多