获取街道名称从地址/目标定位在Android中 [英] Getting street name from Address/Location object in Android

查看:703
本文介绍了获取街道名称从地址/目标定位在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的当前位置的街道名字,但我似乎无法得到它。

I'm trying to get the street name of my current location but I can't seem to get it.

我用这个方法来检索地址:

I use this method to retrieve the Address:

public Address getAddressForLocation(Context context, Location location) throws IOException {

        if (location == null) {
            return null;
        }
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();
        int maxResults = 1;

        Geocoder gc = new Geocoder(context, Locale.getDefault());
        List<Address> addresses = gc.getFromLocation(latitude, longitude, maxResults);

        if (addresses.size() == 1) {
            return addresses.get(0);
        } else {
            return null;
        }
    }

,然后我可以做的事情一样。 address.getLocality() address.getPostal code()

但我要的是街道名称。就像Potterstreet 12。当我打印AddressLine(0)和AddressLine(1)我只得到了邮政code,城市和国家。

But what I want is the street name. Like in "Potterstreet 12". When I print the AddressLine(0) and AddressLine(1) I only get the postalcode, city and country.

我如何可以检索的位置目前,我在这条街叫什么名字?

How can I retrieve the street name of the position i'm currently at?

推荐答案

你有没有尝试过使用 getAddressLine ? 请参见这里更多信息此方法

Have you tried using getAddressLine ? See here for more info on this method

这样的事情应该做(未经测试):

Something like this should do (untested):

for (int i = 0; i < addresses.getMaxAddressLineIndex(); i++) {
 Log.d("=Adress=",addresses.getAddressLine(i));
}

这篇关于获取街道名称从地址/目标定位在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆