how to get the address of center point of GoogleMap v2 in android?

I following this tutorial to get position of center point of v2 GoogleMap .now I want to get the address of the point using reverse geocoding ….

I am using Following code to get LatLang of center point when button is clicked :

   @Override
public void onClick(View view) {
    if(view.getId()==R.id.btn_set_location){

        VisibleRegion visibleRegion = map.getProjection()
                .getVisibleRegion();

        Point x = map.getProjection().toScreenLocation(
                visibleRegion.farRight);

        Point y = map.getProjection().toScreenLocation(
                visibleRegion.nearLeft);

        Point centerPoint = new Point(x.x / 2, y.y / 2);

        LatLng centerFromPoint = map.getProjection().fromScreenLocation(
                centerPoint);



    }
}

I have seen others tutotials to get address using latitude and longitude seperately in my case I have got LatLang ,how to get the address using LatLang..need help here ….if there are others ways to get center point of map and the address of the same point …any kind of help would be appreciated …thank you

Answer

I think, you want to pass LatLang as parameters.I solved the problem with following code:

private class ReverseGeoCoding extends AsyncTask<LatLng, Void, String> {
    Context mContext;


    public ReverseGeoCoding(Context context){
        super();
        mContext = context;
    }

    // Finding address using reverse geocoding
    @Override
    protected String doInBackground(LatLng... params) {
        Geocoder geocoder = new Geocoder(mContext);
        double latitude = params[0].latitude;
        double longitude = params[0].longitude;

        List<Address> addresses = null;
        String addressText="";

        try {
            addresses = geocoder.getFromLocation(latitude, longitude,1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if(addresses != null && addresses.size() > 0 ){
            Address address = addresses.get(0);

            addressText = String.format("%s, %s, %s",
                    address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                    address.getLocality(),
                    address.getCountryName());
        }

        return addressText;
    }

Hope this will work ourt for you>>>

After editing:

You can follow this and if you are working on Activity Class if you working on Fragment class then the following codes will work for you:

new ReverseGeoCoding(getActivity()).execute(centerFromPoint);