以前,我创建了一个在Android Map API v1中扩展GeoPoint的类:
class CyclePoint extends GeoPoint {
public float accuracy;
public double altitude;
public float speed;
public double time;
public CyclePoint(int lat, int lgt, double currentTime) {
super(lat, lgt);
this.time = currentTime;
}
public CyclePoint(int lat, int lgt, double currentTime, float accuracy) {
super(lat, lgt);
this.time = currentTime;
this.accuracy = accuracy;
}
public CyclePoint(int lat, int lgt, double currentTime, float accuracy, double altitude, float speed) {
super(lat, lgt);
this.time = currentTime;
this.accuracy = accuracy;
this.altitude = altitude;
this.speed = speed;
}
}
现在我要切换到V2,我应该扩展什么?它应该是LatLng吗?但是当我切换到LatLng时,它说:类型CyclePoint不能继承最终类LatLng。谁能帮我这个?非常感谢!
答案 0 :(得分:11)
LatLng对象! http://developer.android.com/reference/com/google/android/gms/maps/model/LatLng.html
这个对象非常有用! 你只需要创建一个实例
ex:
LatLng home = new LatLng(-34.3232,-8.31331); // instanciate a new Latlng
home.getLatitude(); // get latitude
home.getLongitude(); // get longitude
ps:纬度和经度必须是双重类型。
答案 1 :(得分:3)
使用合成而不是继承,即将LatLng作为CyclePoint中的字段。