Android 融合位置api从移动数据上的onLocationChnaged方法返回相同的位置
我正在获取当前位置的纬度和经度,但Android 融合位置api从移动数据上的onLocationChnaged方法返回相同的位置,android,fusedlocationproviderapi,Android,Fusedlocationproviderapi,我正在获取当前位置的纬度和经度,但onLocationChanged在移动数据上返回与我使用的PRIORITY\u BALANCED\u POWER\u accurity模式相同的位置 请告诉我哪里出了问题这是我的密码 public class Latlng_Service extends Service implements com.google.android.gms.location.LocationListener, GoogleApiClient.Con
onLocationChanged
在移动数据上返回与我使用的PRIORITY\u BALANCED\u POWER\u accurity
模式相同的位置
请告诉我哪里出了问题这是我的密码
public class Latlng_Service extends Service implements
com.google.android.gms.location.LocationListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
public static String STOP_USER_SERVICE = "STOP_USER_SERVICE";
private static final long INTERVAL = 3000 * 10;
private static final long FASTEST_INTERVAL = 1000 * 5;
private WakeLock wl;
int distance = 0;
List<Address> address_list;
String add_String,cat_id,module_id = "3";
LocationRequest locationRequest;
GoogleApiClient googleApiClient;
Location mloLocation, lastlocation;
String lat, lng, accuracy, name;
String battery_level;
String signal_strength;
Handler fivemiuntesHandler,thirtysecHandler;
Start_latlng_service start_latlng_service;
String login_id, gcm_id, url, response,responseArray[];
boolean flag = false;
List<LatLng> lisLatLngs = new ArrayList<LatLng>();
// public static final String BROADCAST_ACTION =
// "com.xsinfosol.smart_crm.attndance.location";
Intent intent;
String count;
@SuppressWarnings("deprecation")
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
createLocationRequest();
flag = false;
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
googleApiClient.connect();
start_latlng_service = new Start_latlng_service();
this.registerReceiver(this.broadcastReceiver, new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
this.registerReceiver(this.stop_service_at_time, new IntentFilter(
STOP_USER_SERVICE));
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "whatever");
wl.acquire();
return START_STICKY;
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
mloLocation = location;
lat = String.valueOf(location.getLatitude());
lng = String.valueOf(location.getLongitude());
accuracy = String.valueOf(location.getAccuracy());
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
myConnection.logs_onlocation_insert(currentDateTimeString, String.valueOf(location.getLatitude()), String.valueOf(location.getLongitude()));
AtendenceAutoManualFunction(location);
}
@Override
public void onConnectionFailed(ConnectionResult arg0) {
// TODO Auto-generated method stub
System.out.println("Connection Falied " + arg0.getErrorCode());
}
@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
startLocationUpdates();
this.registerReceiver(this.broadcastReceiver, new IntentFilter(
Intent.ACTION_BATTERY_CHANGED));
}
@Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stub
}
protected void createLocationRequest() {
locationRequest = new LocationRequest();
locationRequest
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
locationRequest.setInterval(INTERVAL).setFastestInterval(
FASTEST_INTERVAL);
// .setSmallestDisplacement(10);
// .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
}
protected void startLocationUpdates() {
@SuppressWarnings("unused")
PendingResult<Status> pendingResult = LocationServices.FusedLocationApi
.requestLocationUpdates(googleApiClient, locationRequest, this);
Log.d(TAG, "Location update started ..............: ");
if (fivemiuntesHandler == null) {
Log.d(TAG, "Location update started five minutes ..............: ");
fivemiuntesHandler = new Handler();
fivemiuntesHandler.postDelayed(fiveminutes, 300000);
}
if (thirtysecHandler == null) {
Log.d(TAG, "Location update started five minutes ..............: ");
thirtysecHandler = new Handler();
thirtysecHandler.postDelayed(thirtySec, 0);
}
}
protected void stopLocationUpdates() {
if (googleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(
googleApiClient, this);
}
Log.d(TAG, "Location update stopped .......................");
}
@SuppressWarnings("deprecation")
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
stopLocationUpdates();
googleApiClient.disconnect();
unregisterReceiver(broadcastReceiver);
unregisterReceiver(stop_service_at_time);
sharedPreferences = getSharedPreferences("user_detail",
MODE_WORLD_WRITEABLE);
login_id = sharedPreferences.getString("login_id", "");
gcm_id = sharedPreferences.getString("reg_id", "");
if (!login_id.contentEquals("") && !gcm_id.contentEquals("")
&& flag == false) {
sendBroadcast(new Intent("CantKillMe"));
} else {
wl.release();
stopSelf();
}
}
}
公共类Latlng\u服务扩展了服务实现
com.google.android.gms.location.LocationListener,
GoogleAppClient.ConnectionCallbacks,
GoogleAppClient.OnConnectionFailedListener{
公共静态字符串STOP\u USER\u SERVICE=“STOP\u USER\u SERVICE”;
专用静态最终长间隔=3000*10;
专用静态最终最长最快_间隔=1000*5;
私人WakeLock wl;
整数距离=0;
地址列表;
字符串添加字符串,类别id,模块id=“3”;
位置请求位置请求;
GoogleapClient GoogleapClient;
位置mloLocation,lastlocation;
字符串lat、lng、精度、名称;
串级电池;
串信号强度;
Handler fivemiuntesHandler,30秒Handler;
启动停车服务启动停车服务;
字符串login_id、gcm_id、url、response、responseArray[];
布尔标志=假;
List lisLatLngs=new ArrayList();
//公共静态最终字符串广播\u操作=
//“com.xsinfosol.smart_crm.attendance.location”;
意图;
字符串计数;
@抑制警告(“弃用”)
@凌驾
public void onCreate(){
//TODO自动生成的方法存根
super.onCreate();
StrictMode.ThreadPolicy policy=新建StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(策略);
createLocationRequest();
flag=false;
GoogleapClient=新的GoogleapClient.Builder(此)
.addApi(LocationServices.API).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this.build();
googleApiClient.connect();
start_LATLING_服务=新的start_LATLING_服务();
this.registerReceiver(this.broadcastReceiver,新的IntentFilter(
意图。行动(电池更换);
this.registerReceiver(this.stop\u服务,新的意向过滤器(
停止(用户(服务));
}
@凌驾
公共IBinder onBind(意图arg0){
//TODO自动生成的方法存根
返回null;
}
@凌驾
公共int onStartCommand(Intent Intent、int标志、int startId){
//TODO自动生成的方法存根
PowerManager pm=(PowerManager)getSystemService(Context.POWER\u服务);
wl=pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_引起_WAKEUP,“随便什么”);
wl.acquire();
返回开始时间;
}
@凌驾
已更改位置上的公共无效(位置){
//TODO自动生成的方法存根
位置=位置;
lat=String.valueOf(location.getLatitude());
lng=String.valueOf(location.getLongitude());
精度=String.valueOf(location.getAccurance());
字符串currentDateTimeString=DateFormat.getDateTimeInstance().format(新日期());
myConnection.logs\u onlocation\u insert(currentDateTimeString,String.valueOf(location.getLatitude()),String.valueOf(location.getLatitude());
AtendenceAutoManualFunction(位置);
}
@凌驾
连接失败的公共void(连接结果arg0){
//TODO自动生成的方法存根
System.out.println(“连接故障”+arg0.getErrorCode());
}
@凌驾
未连接的公共空间(捆绑arg0){
//TODO自动生成的方法存根
startLocationUpdates();
this.registerReceiver(this.broadcastReceiver,新的IntentFilter(
意图。行动(电池更换);
}
@凌驾
连接上的公共无效已暂停(int arg0){
//TODO自动生成的方法存根
}
受保护的void createLocationRequest(){
locationRequest=新的locationRequest();
定位请求
.setPriority(位置请求、优先级、功率、精度);
locationRequest.setInterval(INTERVAL).SetFastTestInterval(
最快间隔);
//.最小位移(10);
//.setPriority(位置请求、优先级、功率、精度);
}
受保护的void startLocationUpdates(){
@抑制警告(“未使用”)
Pendingreult Pendingreult=LocationServices.FusedLocationApi
.RequestLocationUpdate(GoogleAppClient、locationRequest、this);
Log.d(标记“位置更新已开始…”);
if(fivemiuntesHandler==null){
Log.d(标签“位置更新开始五分钟……”);
fivemiuntesHandler=新处理程序();
五分钟后延迟(五分钟,300000);
}
if(thirtysecHandler==null){
Log.d(标签“位置更新开始五分钟……”);
thirtysecHandler=新处理程序();
thirtysecHandler.postDelayed(三十秒,0);
}
}
受保护的void stopLocationUpdates(){
if(googleApiClient.isConnected()){
LocationServices.FusedLocationApi.RemovelocationUpdate(
GoogleapClient,这个);
}
Log.d(标记“位置更新已停止…”);
}
@抑制警告(“弃用”)
@凌驾
公共空间{
//TODO自动生成的方法存根
super.ondestory();
stopLocationUpdates();
googleApiClient.disconnect();
未注册接收器(广播接收器);
取消注册接收者(在指定时间停止服务);
SharedReferences=GetSharedReferences(“用户详细信息”,
模式(世界)(可写);;
login_id=SharedReferences.getString(“login_id”,即“”);
gcm_id=SharedReferences.get