I am trying to implement a map with a button that will animate back to the user's current position. I am having a hard time trying to find a way to access my MapController from inside the OnClickListener.
I have searched through SO but haven't found a proper answer to my problem.
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
}
}
}
I cannot set MapController
and LocationMager
to final as they are initialized in onCreate
.
Is there any way to achieve this?