簡體   English   中英

無法解析onCreate或getMapAsync

[英]Cannot resolve onCreate or getMapAsync

我的代碼中有兩個錯誤..以下幾行有錯誤。 無法解析onCreate()方法和getMapAsync()。 我已經完成了使緩存無效並重新啟動的操作,但這並沒有幫助。 請幫我解決這個問題。

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) {

  }
}

不返回任何內容: map = mapView.getMapAsync();

采用:

  mapView.getMapAsync(this);

然后在onMapReady()獲取Map對象

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM