参考下面的代码.. 我有一个类 LocationService 并有一个变量纬度。我想在另一个类 Post 中使用该变量。我怎么做。基本上我想得到我在其他班级也从那里得到的纬度和经度。因为我想将它发布在服务器上。那我该怎么做。
定位服务.java
public class LocationService extends Service{
Context context;
WakeLock wl;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
public int onStartCommand(Intent intent, int flags, int startId) {
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
wl.acquire();
context = this;
final String who = intent.getStringExtra("who");
final LocationManager locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
final LocationListener listener = new LocationListener(){
// start location changed
public void onLocationChanged(Location loc) {
double latitude = loc.getLatitude();
double longitude = loc.getLongitude();
......
......
}
Post.java
public class Post extends LocationService {
}
编辑Post.java
public class Post extends LocationService {{
super.latitude = loc.getLatitude();
}
}
这会让我从 LocationService 类到 Post 类的纬度..?