你不能这样做. (位置不是EasyLocation.)
你通常会做这样的事情:
public class EasyLocation extends android.location.Location {
public EasyLocation(Location loc) {
// copy data from loc to this.
super(loc);
}
...
public long getElapsedTime() {
return getTime() - System.currentTimeMillis();
}
}
而不是做
lastNetworkLocation =
(EasyLocation) locationManager.getLastKnownLocation(
LocationManager.NETWORK_PROVIDER);
你做
lastNetworkLocation =
new EasyLocation(locationManager.getLastKnownLocation(
LocationManager.NETWORK_PROVIDER));
请记住,虽然大多数人可能会说“赞成组合而非继承”,然后继续使用
public class EasyLocation {
Location loc;
public EasyLocation(Location loc) {
this.loc = loc;
}
public long getElapsedTime() {
return getTime() - System.currentTimeMillis();
}
public Location getLocation() {
return loc;
}
}