Android 无法生成GPS位置

Android 无法生成GPS位置,android,Android,我尝试了上面的代码通过网络生成当前GPS位置。但当我尝试时,我得到了以下错误。我使用此代码作为后台服务。您能告诉我为什么会发生此错误吗 protected JSONObject doWork() { Location location; Double latitude = 0.0; locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); i

我尝试了上面的代码通过网络生成当前GPS位置。但当我尝试时,我得到了以下错误。我使用此代码作为后台服务。您能告诉我为什么会发生此错误吗

protected JSONObject doWork() {

        Location location;
        Double latitude = 0.0;
 locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        isGPSEnabled = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);

        // getting network status
        isNetworkEnabled = locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        if (!isGPSEnabled && !isNetworkEnabled) {
            // no network provider is enabled
        }

        else {
            this.canGetLocation = true;
            // First get location from Network Provider
            if (isNetworkEnabled) {
                locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES,
                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("Network", "Network");
                if (locationManager != null) {
                    location = locationManager
                            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    if (location != null) {
                        Log.i("Provider", provider + " has been selected.");
                        latitude = location.getLatitude();
                        onLocationChanged(location);
                    }

                }
                // latitude = location.getLatitude();
                // longitude = location.getLongitude();
            }
        }
        JSONObject result = new JSONObject();
           try {

            String msg = "KAsun " + mHelloTo + " - its currently "
                    + latitude.toString();
            result.put("Message", msg);

            Log.d(TAG, msg);

        } catch (JSONException e) {
        }

        return result;

看看这个。。。这有更多的解释。。看看这些线程,这里我没有使用任何Toast。这种方法是在后台服务上运行的。你调试过你的代码吗????哪一行抛出错误??
 12-27 09:34:39.406: I/BackgroundService(14495): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()