Android地理编码asynctask崩溃

时间:2015-01-27 09:27:40

标签: android android-asynctask

单击按钮时,我的android asynctask崩溃了。以下是代码:

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

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

    @Override
    protected LatLng doInBackground(String... params){

        Geocoder gc =  new Geocoder(mContext);
        List<Address> addresses = null;
        try {
            /*
            * Return 1 address.
            */
            String location = edit.getText().toString();
            addresses = gc.getFromLocationName(location, 1);
        } catch (IOException e1) {
            Log.e("LocationSampleActivity", "IO Exception in getFromLocation()");
            e1.printStackTrace();
        } catch (IllegalArgumentException e2) {
            e2.printStackTrace();
        }

        if (addresses != null && addresses.size() > 0) {

            Address address = addresses.get(0);

            double lat = address.getLatitude();
            double lng = address.getLongitude();

            LatLng mint = new LatLng(lat,lng);

            return mint;
        }

    else {
            return null;
        }
    }

    @Override
    protected void onPostExecute (LatLng mint) {
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(mint,14);
        map.moveCamera(update);
        progress.dismiss();
    }
}

0 个答案:

没有答案