Async task not doing anything

时间:2016-04-04 16:49:15

标签: android multithreading google-maps android-asynctask

I have created a infowindow for a marker and trying to set the address of a particular location by tapping on it but its not doing anything. Where am I making mistake?

map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) {
        LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = layoutInflater.inflate(R.layout.info_window, null, false);
        anchor_name = (TextView) view.findViewById(R.id.ancor_name);
        anchor_address = (TextView) view.findViewById(R.id.address_a);
        LatLng latlng = marker.getPosition();
        AsyncTask<LatLng, Void, String> mytask = new AsyncTask<LatLng, Void, String>() {

            @Override
            protected String doInBackground(LatLng... params) {
                return getParticularLocationAddress(params[0]);
            }
            @Override
            protected void onPostExecute(String result) {
                anchor_address.setText(result);
                anchor_name.setText("Ravi");
            }
        };
        mytask.execute(latlng);
        //anchor_address.setText(getParticularLocationAddress(latlng));
        return view;
    }
});

getParticularLocationAddress method is given as

public String getParticularLocationAddress(LatLng latlng) {
    double longitude = latlng.longitude;
    double latitude = latlng.latitude;
    String marker_address = null;
    try {
        if (longitude != 0) {
            Geocoder geo = new Geocoder(this.getApplicationContext(), Locale.getDefault());
            addresses = geo.getFromLocation(latitude, longitude, 1);
            marker_address = addresses.get(0).getAddressLine(0) + ", "
                    + addresses.get(0).getAddressLine(1);
        } else {
            marker_address = "Can't resolve";
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return marker_address;
}

0 个答案:

没有答案