位置服务deosn不返回冰淇淋sanwditch的当前位置

时间:2015-04-06 09:43:51

标签: android location android-4.0-ice-cream-sandwich

我正在开发一个获取当前用户位置的应用程序..我的代码在jillybean,kitkat,棒棒糖上工作正常..但在冰淇淋三明治上它返回我的最后位置而不是我当前的位置 这是我的代码

 public void getLocation() {
    // Define the criteria how to select the locatioin provider -> use
    // default
    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, false);
    List<String> providers = locationManager.getProviders(true);
    for (String provider : providers) {
        locationManager.requestLocationUpdates(provider, 1000, 0,
                new LocationListener() {
                    public void onLocationChanged(Location location) {
                        Globals.latitude=location.getLatitude();
                        Globals.longitude=location.getLongitude();
                    }

                    public void onProviderDisabled(String provider) {
                    }

                    public void onProviderEnabled(String provider) {
                    }

                    public void onStatusChanged(String provider,
                            int status, Bundle extras) {
                    }
                });
        Location location = locationManager.getLastKnownLocation(provider);

        // Initialize the location fields
        if (location != null) {
            System.out.println("Provider " + provider
                    + " has been selected.");
            onLocationChanged(location);
        } else {
            location = locationManager
                    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (location != null) {
                System.out.println("Provider " + provider
                        + " has been selected.");
                onLocationChanged(location);
            }
            Globals.latitude = -1;
            Globals.longitude = -1;
        }
    }
}

0 个答案:

没有答案