我有一种获取设备当前位置的方法,我想将其值设置为分配给 onCreate 中的 LatLng 变量。我确信这是一个简单的修复,但我想不出解决方案.有人可以为此提供解决方案吗?
在下面的代码中更容易解释这一点:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.journey_planner);
//Get direction between from and to positions
//want to set fromposition to point to the values of lat and long in below method onCreate
LatLng fromPosition = new LatLng(13.687140112679154, 100.53525868803263);
LatLng toPosition = new LatLng(13.683660045847258, 100.53900808095932);
}
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
}
最佳答案
如果我对这个问题的理解正确,你会希望将你的 lat 和 lng 设为像@Clay 所说的类变量
int lat;
int lng;
然后你可以设置你的fromPosition
protected void onCreate(Bundle savedInstanceState) {
...
LatLng fromPosition = new LatLng(lat, lng);
...
}
关于android - 如何将公共(public)方法变量的值设置为 protected 方法中的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21268778/