检索服务定位 [英] Retrieve location from Service
本文介绍了检索服务定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个服务,谁听用户的位置。
I'm trying to do a service, who listen user's location.
code波纹管:
public class ServiceBeezer extends Service implements
OnConnectionFailedListener, ConnectionCallbacks {
private LocationRequest mLocationRequest;
private LocationClient mLocationClient;
public ServiceBeezer() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// 1. init locationrequest
mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_NO_POWER);
mLocationRequest.setFastestInterval(1000);
// 2. mlocationclient
mLocationClient = new LocationClient(this, this, this);
return START_STICKY;
}
@Override
public void onConnected(Bundle arg0) {
Toast.makeText(this,
getClass().getSimpleName() + "onConnected: " + arg0,
Toast.LENGTH_LONG).show();
}
@Override
public void onDisconnected() {
Toast.makeText(this, getClass().getSimpleName() + "onDisconnected: ",
Toast.LENGTH_LONG).show();
}
@Override
public void onConnectionFailed(ConnectionResult arg0) {
Toast.makeText(this,
getClass().getSimpleName() + "onConnectionFailed: " + arg0,
Toast.LENGTH_LONG).show();
}
}
但 onConnected()
, onDisconnected()
和 onConnectionFailed()
永远不会被调用。
我做错了吗?
我还有其他的LocationRequest和LocationClient内的活动。
I have other LocationRequest, and LocationClient inside on Activity.
可以在此问题?
推荐答案
如果我没看错你有没有叫mLocationClient.connect()在$ C $随时随地c您上面粘贴的。
If I am not wrong you haven't called mLocationClient.connect() anywhere in the code you pasted above.
这篇关于检索服务定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文