我有一個方法來獲取設備的當前位置,我想將它的值設置爲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());
}
你爲什麼不嘗試使緯度和經度類變量所以你的創建者可以訪問他們? – Ogen