简体   繁体   English

无法解析onCreate或getMapAsync

[英]Cannot resolve onCreate or getMapAsync

I have two errors in my code .. the following lines have the errors. 我的代码中有两个错误..以下几行有错误。 Cannot resolve onCreate() method and getMapAsync(). 无法解析onCreate()方法和getMapAsync()。 I have done invalidate caches and restart but it didn't help. 我已经完成了使缓存无效并重新启动的操作,但这并没有帮助。 Please help me solve this issue. 请帮我解决这个问题。

mapView.onCreate(savedInstanceState); mapView.onCreate(savedInstanceState);

map = mapView.getMapAsync(); 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(); 不返回任何内容: map = mapView.getMapAsync();

use: 采用:

  mapView.getMapAsync(this);

then inside onMapReady() get the Map object 然后在onMapReady()获取Map对象

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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