小编mal*_*gno的帖子

根据当前和某个位置之间的距离更改 LocationRequest 的间隔

我想通过使用 Fused Location API 更改更新间隔来节省电量。距离某个位置越远,间隔就应该越大。

public class service extends Service implements GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener,LocationListener {
    private LocationRequest locationrequest;
    private LocationClient locationclient;



    @Override
    public void onCreate() {

        int resp = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (resp == ConnectionResult.SUCCESS) {
            locationclient = new LocationClient(this, this, this);
            locationclient.connect();
        } else {
            Toast.makeText(this, "Google Play Service Error " + resp, Toast.LENGTH_LONG).show();

        }

    }



    @Override
    public void onDestroy() {
        super.onDestroy();
        if(locationclient!=null)
            locationclient.disconnect();
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        Log.i(TAG, "onConnected"); …
Run Code Online (Sandbox Code Playgroud)

gps android location

5
推荐指数
1
解决办法
6253
查看次数

标签 统计

android ×1

gps ×1

location ×1