简体   繁体   中英

Cannot resolve onCreate or getMapAsync

I have two errors in my code .. the following lines have the errors. Cannot resolve onCreate() method and getMapAsync(). I have done invalidate caches and restart but it didn't help. Please help me solve this issue.

mapView.onCreate(savedInstanceState);

map = mapView.getMapAsync();

public class PlacesMapActivity extends Fragment implements OnMapReadyCallback {
   private MapView mapView;
   private GoogleMap map;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.map_places, container, false);
    // Gets the MapView from the XML layout and creates it
    mapView = (MapView) v.findViewById(R.id.map);
    mapView.onCreate(savedInstanceState);

    // Gets to GoogleMap from the MapView and does initialization stuff
    map = mapView.getMapAsync();
    map.getUiSettings().setMyLocationButtonEnabled(false);
    map.setMyLocationEnabled(true);

    // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
    try {
        MapsInitializer.initialize(this.getActivity());
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }
    // Updates the location and zoom of the MapView
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
    map.animateCamera(cameraUpdate);

    return v;

   }

   @Override
   public void onMapReady(GoogleMap googleMap) {

  }
}

Do not return anything: map = mapView.getMapAsync();

use:

  mapView.getMapAsync(this);

then inside onMapReady() get the Map object

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM