我有一个从api获取数据的服务。我想实现一个位置管理器,这样我就可以获得用户位置并更新lat和lng。 我有这个每分钟刷新一次的服务,并通过调用LoadPlaces(它创建一个对象)从API加载数据。所以我想得到用户的lat和lng并将其传递给对象。 代码如下。有帮助吗? 感谢
public class DownloadPlaceService extends Service {
Double lat, lng;
public DownloadPlaceService() {
}
private static final String TAG = "TAG";
private LocationManager mLocationManager = null;
private static final int LOCATION_INTERVAL = 400;
protected LocationManager locationManager;
protected LocationListener locationListener;
@Override
public void onCreate() {
super.onCreate();
Log.i("StartCommand", "started");
lat = 42.01;
lng = 21.22;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//locationManager.requestLocationUpdates("gps", 0, 0, locationListener);
final Context context = this;
Log.w("Coordinates",lat+"");
LoadPlaces reloadPersons = new LoadPlaces(
this,
new onDownloadPlaceDatabaseNotification(this),
lat,
lng
);
reloadPersons.execute();
Log.i("StartCommand","reloaded persons");
return super.onStartCommand(intent, flags, startId);
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}