package cn.ccy.test_weather.location;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

public class AutoLocation extends Service{
	
	public static LocationClient mLocationClient;
	public static String TAG = "System.out";
	private static final int UPDATE_TIME = 5000;
	public MyLocationListenner myListener = new MyLocationListenner(this);
		
	
	public void onCreate() {
		super.onCreate();
		mLocationClient = new LocationClient(getApplication());
		
	}
	public int onStartCommand(Intent intent, int flags, int startId) {
		mLocationClient.registerLocationListener(myListener);
		setLocationOption();
		mLocationClient.start();
		Log.v(TAG,"开始定位！");
		return super.onStartCommand(intent, flags, startId);
		
	}
	@Override
	public void onDestroy() {
		Log.v(TAG,"定位服务 onDestroy");
		super.onDestroy();
	}
	
	
	private void setLocationOption() {
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(true); // 打开gps
		option.setCoorType("bd09ll"); // 设置坐标类型
		option.setServiceName("com.baidu.location.service");
		option.setScanSpan(UPDATE_TIME);
		option.setPoiExtraInfo(true);
		option.setAddrType("all");
		option.setScanSpan(Integer.parseInt("300")); // 设置定位模式，小于1秒则一次定位;大于等于1秒则定时定位
		option.setPriority(LocationClientOption.NetWorkFirst); // 设置网络优先
		// option.setPriority(LocationClientOption.GpsFirst); // 默认是gps优先
		option.setPoiNumber(10);
		option.disableCache(true);
		mLocationClient.setLocOption(option);

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