ユーザーの現在の位置に戻るボタンを使用してマップを実装しようとしています。OnClickListener 内から MapController にアクセスする方法を見つけるのに苦労しています。
SO を検索しましたが、問題に対する適切な回答が見つかりませんでした。
public class MainActivity extends MapActivity implements LocationListener
{
private LimitedZoomMapView mapView;
private MapController mapController;
private Gallery gallery;
private ImageButton centerPositionButton;
// [...]
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.mapView = (LimitedZoomMapView) findViewById(R.id.mapview);
this.mapView.setBuiltInZoomControls(true);
this.locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// [...]
this.centerPositionButton = (ImageButton) findViewById(R.id.centerposbutton);
this.centerPositionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Access MapController and LocationManager from here
}
}
}
MapController
と で初期化されているため、LocationMager
最終的に設定できませんonCreate
。
これを達成する方法はありますか?