0

ユーザーの現在の位置に戻るボタンを使用してマップを実装しようとしています。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

これを達成する方法はありますか?

4

1 に答える 1

0
    used map v2


        map = ((SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map)).getMap();

            Cursor c = adp.getaddress(surname);// get address from the database
            c.moveToFirst();
            adderess = c.getString(c.getColumnIndex(SQLiteAdapter.KEY_CONTENT3));// get
                                                                                    // address
                                                                                    // in
                                                                                    // string
                                                                                    // for
                                                                                    // used
                                                                                    // location
                                                                                    // for
                                                                                    // the
                                                                                    // map

            /* get latitude and longitude from the adderress */

            Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
            try {
                List<Address> addresses = geoCoder.getFromLocationName(adderess, 5);
                if (addresses.size() > 0) {

                    Double lat = (double) (addresses.get(0).getLatitude());
                    Double lon = (double) (addresses.get(0).getLongitude());

                    Log.d("lat-long", "" + lat + "......." + lon);
                    final LatLng user = new LatLng(lat, lon);
                    /*used marker for show the location */
                    Marker hamburg = map.addMarker(new MarkerOptions()
                            .position(user)
                            .title(adderess)
                            .icon(BitmapDescriptorFactory
                                    .fromResource(R.drawable.marker)));
                    // Move the camera instantly to hamburg with a zoom of 15.
                    map.moveCamera(CameraUpdateFactory.newLatLngZoom(user, 15));

                    // Zoom in, animating the camera.
                    map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }



   <fragment
                    android:id="@+id/map"
                    android:layout_width="match_parent"
                    android:layout_height="150dip"
                    android:layout_marginLeft="35dp"
                    android:layout_marginRight="35dp"
                    android:layout_marginTop="20dp"
                    class="com.google.android.gms.maps.SupportMapFragment" />
于 2013-06-18T10:20:43.660 に答える