package com.zkjc.common.gps;

import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.jess.arms.utils.ArmsUtils;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
import okhttp3.RequestBody;
import timber.log.Timber;

public class LocationService extends Service {


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




    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        System.out.println("onStartCommand");
        GPSLocationManager instances = GPSLocationManager.getInstances(this);
        instances.setScanSpan(1000);
        instances.start(new GPSLocationListener() {
            @Override
            public void UpdateLocation(Location location) {

                SharedPreferences sharedPreferences = getSharedPreferences("sys", MODE_PRIVATE);
                SharedPreferences.Editor edit = sharedPreferences.edit();

                double latitude = location.getLatitude();
                double longitude = location.getLongitude();
                edit.putString("locationLatitude", latitude + "");
                edit.putString("locationLongitude", longitude + "");
                edit.commit();
                Log.e("经纬度", latitude + "--222-" + longitude);
            }

            @Override
            public void UpdateStatus(String provider, int status, Bundle extras) {

            }

            @Override
            public void UpdateGPSProviderStatus(int gpsStatus) {

            }
        });


        return super.onStartCommand(intent, flags, startId);

    }
}
