无法解析方法setBuiltInZoomControls& getController

时间:2016-04-03 18:04:36

标签: java android google-maps

我使用的MapsActivity错误显示cannot resolve method 'setBuiltInZoomControls(boolean)'

cannot resolve method 'getController()'

cannot resolve method 'setUseDataConnection(boolean)'

这是我的MapsActivity.java

    package com.example.app6;

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;

    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.MapView;
    import com.google.android.gms.maps.OnMapReadyCallback;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.MarkerOptions;
    import com.google.android.gms.vision.barcode.Barcode;

    public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

        GoogleMap mMap;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            mapFragment.getMapAsync(this);
            MapView mapView = new MapView(this, 256);
            mapView.setClickable(true);
            mapView.setBuiltInZoomControls(true);
            setContentView(mapView);
            mapView.getController().setZoom(14);    
            mapView.getController().setCenter(new Barcode.GeoPoint(52.221,6.893));
mapView.setUseDataConnection(false);

        }
        @Override
        public void onMapReady(GoogleMap googleMap) {
            mMap = googleMap;

            // Add a marker in Jaipur and move the camera
            LatLng jpr = new LatLng(26.8473727, 75.8104005);
            mMap.addMarker(new MarkerOptions().position(jpr).title("Marker in Jaipur"));
            mMap.moveCamera(CameraUpdateFactory.newLatLng(jpr));
        }
    }

1 个答案:

答案 0 :(得分:0)

问题是您使用的是com.google.android.gms.maps.MapView;

但要在mapView上使用setBuiltInZoomControls(),您应该使用com.google.android.maps.MapView

问题是你正在尝试新旧 Google Maps API

<com.google.android.maps.MapView
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:id="@+id/mapview"
   android:clickable="true"
   android:apiKey="your key">

但我的建议是;使用最新版本的Google Maps Android API