如何在Geocoder中关闭progressDialog

时间:2017-01-19 10:08:16

标签: android progressdialog

如何在使用地理编码器的反向地理编码中关闭progressDialog,下面是我尝试过的代码,我在onClick事件中初始化progressDialog并试图解除如下

private void GetCurrentLocation() {

    gps = new GPSTracker(Example.this);

    // check if GPS enabled
    if (gps.canGetLocation()) {
        double latitude = gps.getLatitude();
        double longitude = gps.getLongitude();
        System.out.println(latitude);
        System.out.println(longitude);
        //Get address base on location

        pd.dismiss();

        geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
        try {

            addresses = geocoder.getFromLocation(latitude, longitude, 1);
            if (null != addresses && addresses.size() > 0) {

                String Location = addresses.get(0).getSubLocality();

                if (Location.length() != 0) {

                    txtlocationview.setText(Location);

                } else {
                    txtlocationview.setText("");
                }
            }

        } catch (IOException e) {
            e.printStackTrace();

        }
        pd.dismiss();
    } else {
        gps.showSettingsAlert();
    }

}

但是ProgressDialog没有被贬低

0 个答案:

没有答案