我的代码中有两个错误..以下行有错误。无法解析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) {
}
}
答案 0 :(得分:0)
不要退货:map = mapView.getMapAsync();
使用:
mapView.getMapAsync(this);
然后在onMapReady()
内获取Map对象
@Override
public void onMapReady(GoogleMap googleMap) {
map= googleMap;
}