0

我是 android 新手,我想显示我当前的位置,如“巴基斯坦拉合尔 johar 镇”。请问有什么帮助吗?

提前致谢。

4

2 回答 2

0

获取当前的纬度和经度使用: LocationManager

LocationManager locationmanager = (LocationManager) getSystemService(LOCATION_SERVICE);
        Criteria cr = new Criteria();
        String provider = locationmanager.getBestProvider(cr, true);
        Location location = locationmanager.getLastKnownLocation(provider);
        if (location != null) {
            double lat=location.getLatitude();
        double lng=location.getLongitude();
        }

将当前纬度和经度传递给以下方法,它将返回您的地址!

public List<Address> getAddress(double latitude, double longitude) {
        List<Address> addresses = null;
        try {

            Geocoder geocoder;

            geocoder = new Geocoder(youractivityname.this);
            if (latitude != 0 || longitude != 0) {
                addresses = geocoder.getFromLocation(latitude, longitude, 1);

                //testing address below 

                String address = addresses.get(0).getAddressLine(0);
                String city = addresses.get(0).getAddressLine(1);
                String country = addresses.get(0).getAddressLine(2);
                Log.d("TAG", "address = " + address + ", city =" + city
                        + ", country = " + country);

            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            // Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
        return addresses;
    }
于 2013-07-23T06:48:04.610 回答
0

首先,您必须找到您的位置,因此请关注以下帖子: 当前位置和此处当前位置

然后找地方,看看这里 用户周围的地方列表

于 2013-07-23T06:49:44.017 回答