这是可以实现它,让你的服务类像下面
这里的途径之一,
与此的ScheduledThreadPoolExecutor您的服务将在后台 ,你将需要的LocationManager
您SERVICE.class延长服务实现LocationListener的,可运行
private LocationManager mgr = null;
private ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
@Override
public void onCreate() {
//check gps is on/off
//get locationmanager
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//check if internet is on/off
setBeforeDelay15();
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onLocationChanged(Location location) {
//re-execute at time you need with **scheduleAtFixedRate**
}
@Override
public void run() {
//here get the best location from two ways 1>gps and 2>network provider
//once you get this insert to database
//set delay then request call method again
}
@Override
public void onDestroy() {
//if locationmanager is not null then remove all updates
}
private void setDelay15() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// Log.e("srop self by", "delay15");
startWork();
}
}, 300000);//120000
}
private void startWork() {
//check here for 1>gps and 2>network provider
//get location and save it
}
使用此,当您需要位置在您的应用程序。
只需使用谷歌的地方API为Android,它的快速和容易。 它使用http请求,所以它不会是一个问题的android – PauAI
好吧,但没有找到任何与后台服务,使用谷歌Places API查找的例子。 – Kumar
https://developers.google.com/places/android-api/current-place – PauAI