Can someone help me solve this execution error please, I'm trying to show a map, in a fragment, I'm working from the template of a navigationDrawer. I have generated a fragment that contains the following code:
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapActivity extends Fragment implements OnMapReadyCallback {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.map_layout, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.map);
fragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng bogota = new LatLng(4.653421, -74.145150);
googleMap.addMarker(new MarkerOptions().position(bogota)
.title("Uniagustiniana"));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(bogota, 16.1f));
}
public interface OnFragmentInteractionListener {
void onFragmentInteraction(Uri uri);
}
The following is the code map_layout.xml
FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemasandroid.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tecnologias.uniagustinianaapp.MapActivity">
<fragment android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"></fragment>
/FrameLayout
The errors in the Android Monitor come out this way when I try to execute this fragment only. The error refers to this line: fragment.getMapAsync (this);