FusedLocationApi出现意外行为

时间:2014-12-06 09:05:21

标签: android google-play-services android-wifi android-location

我目前正在开发一个应用程序,需要在使用时定位用户。

我的问题如下,我正在使用FusedLocationApi,一切似乎都适用于Android 4.3版本以下的手机。所有wi-fi,3g和gps都会返回位置更新。然而,使用三星S4,Note3(Android 4.4+版本的新手机)我无法使用Wi-Fi或3g进行位置更新,但只能使用GPS。这是我的代码片段

 private ConnectionCallbacks mConnectionCallbacks = new ConnectionCallbacks() {
    @Override
    public void onConnected(Bundle arg0) {
        Toast.makeText(mCtx, "Google Play Services connected, requesting location updates", Toast.LENGTH_SHORT).show();
        LocationRequest locationRequest = LocationRequest.create();
        locationRequest.setInterval(3000);
        locationRequest.setFastestInterval(1000);
        locationRequest.setNumUpdates(1);
        locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);

        LocationServices.FusedLocationApi.requestLocationUpdates(
                mGoogleApiClient, locationRequest, mLocationListener);
    }

    @Override
    public void onConnectionSuspended(int i) {

    }
};

private LocationListener mLocationListener = new LocationListener() {

    @Override
    public void onLocationChanged(Location location) {
        Toast.makeText(mCtx, "Found location from: " + location.getProvider(), Toast.LENGTH_LONG).show();
        LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener);
        new AsyncFetchAddress().execute(location);
    }
};

private OnConnectionFailedListener mConnectionFailedListener = new OnConnectionFailedListener() {

    @Override
    public void onConnectionFailed(ConnectionResult arg0) {
        Toast.makeText(mCtx, "Connection to Play Services failed",
                Toast.LENGTH_LONG).show();
    }
};

这是api connect

if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx) == ConnectionResult.SUCCESS) {
        Toast.makeText(mCtx, "Google Play Services avaliable", Toast.LENGTH_SHORT).show();

        mGoogleApiClient = new GoogleApiClient.Builder(mCtx)
                .addApi(LocationServices.API)
                .addConnectionCallbacks(mConnectionCallbacks)
                .addOnConnectionFailedListener(mConnectionFailedListener)
                .build();

        mGoogleApiClient.connect();
    } else {
        Toast.makeText(mCtx, "Google Play Services not available, canceling location update", Toast.LENGTH_SHORT).show();
    }

Google Play服务可用,它会请求位置更新(使用toast调试)

您认为我的问题是什么?为什么它不适用于wi-fi或3g而只能使用更新的手机gps(可能与Android版本有关,4.4.2在这些手机上)

由于

0 个答案:

没有答案