【问题标题】:Can't get the cityname of a particular area in android google map无法在android谷歌地图中获取特定区域的城市名称
【发布时间】:2014-03-24 06:54:05
【问题描述】:

在我的应用程序中,我使用了谷歌地图,根据经纬度成功我可以得到地区、州、密码、国家,我的代码如下

Geocoder gcd = new Geocoder(Map.this, Locale.getDefault());
                    List<Address> addresses;
                    try {
                        addresses = gcd.getFromLocation(draggedlat, draggedlng,
                                1);
                        if (addresses.size() > 0) {
                            Log.d("CityName", "---->"
                                    + addresses.get(0).getLocality()
                                    + addresses.get(0).getAddressLine(1)
                                    + addresses.get(0).getAddressLine(2)
                                    + addresses.get(0).getFeatureName());

                            Log.d("Locality", "Locality"
                                    + addresses.get(0).getSubLocality());

                        } else {
                            Toast.makeText(Map.this,
                                    "Try with some other city..",
                                    Toast.LENGTH_SHORT).show();
                        }
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

现在我的问题是必须找到特定区域的城市名称。那可能吗??请帮助我。

我的输出是:

VanapatlaVanapatla, Andhra Pradesh 509235,India,Kollapur Rd

提前致谢!

【问题讨论】:

  • 返回此行的内容:addresses.get(0).getLocality()
  • 查看我的输出。
  • 仍然没有返回任何东西..然后尝试使用其他坐标进行测试,看看它是否返回了一些东西。
  • 我试过了,但这是我得到的所有位置的输出,这意味着输出的形式相同(地区、州、密码、国家)

标签: android google-maps geocode


【解决方案1】:

用不同的点试试这个:

List<Address> list = geoCoder.getFromLocation(location
            .getLatitude(), location.getLongitude(), 1);
    if (list != null & list.size() > 0) {
        Address address = list.get(0);
        result = address.getLocality();
        return result;

【讨论】:

  • 我用过这个但没有运气。得到相同的输出
  • 我通过 (list.get(0).getSubAdminArea(); ) 这个方法得到了解决方案.. 无论如何感谢您的详细信息。
  • 很好......但 getSubAdminArea() 不会总是返回城市名称。返回地址所属的子行政区名称
  • [Address[addressLines=[0:"Bajanaikoill St",1:"Appur RF, Tamil Nadu 603204",2:"India"],feature=Bajanaikoill St,admin=Tamil Nadu,sub -admin=Kanchipuram,locality=Appur RF,thoroughfare=Bajanaikoill St,postalCode=603204,countryCode=IN,countryName=India]] 这是一个地址的总列表,“sub-admin=Kanchipuram”,通过sub admin我们可以获取特定区域的城市。
猜你喜欢
  • 1970-01-01
  • 2012-12-27
  • 1970-01-01
  • 2023-03-20
  • 2018-01-16
  • 2012-04-04
  • 1970-01-01
  • 2016-08-04
  • 2016-11-21
相关资源
最近更新 更多