这是我为Google Map项目编写的代码。但它在行号上提示错误。 271在getMapAsync()。
private void setUpMap(double lat,double lon) {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync();
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lon)));
mMap.animateCamera(CameraUpdateFactory.zoomTo(16.0f));
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latLng) {
try {
new GetPlacesAsyncTask().execute(latLng.latitude, latLng.longitude);
} catch (Exception ex) {
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
}
}
}}
答案 0 :(得分:1)
你需要将“new OnMapReadyCallback()”传递给getMapAsync()方法,如下所示: -
getMapAsync(new OnMapReadyCallback(){}):