Issue
I'm trying to set Google Maps in my Support Fragment but the map is not being loaded, all I have is the default grid displayed by Google Maps. I set it in an Activity and all works fine, that is the reason why I think that the problem is that I'm using it inside an android.support.v4.app.Fragment
public class DetalleRuta extends android.support.v4.app.Fragment {
private GoogleMap googleMap;
private MapView mapView;
public DetalleRuta() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_detalle_ruta, container, false);
//Inicio el mapa
mapView = (MapView)v.findViewById(R.id.mapa);
mapView.onCreate(savedInstanceState);
googleMap = mapView.getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
int idRuta = this.getArguments().getInt("identificador_ruta");
return v;
}
}
And here is the .xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.fitness.dullmonkey.keepingfit.DetalleRuta"
android:weightSum="10">
<com.google.android.gms.maps.MapView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7"
android:id="@+id/mapa">
</com.google.android.gms.maps.MapView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="3"
android:paddingTop="20dp">
<TextView android:text="@string/hello_world" android:layout_width="match_parent"
android:layout_height="wrap_content" android:gravity="center" android:id="@+id/distancia"/>
<TextView android:text="@string/hello_world" android:layout_width="match_parent"
android:layout_height="wrap_content" android:gravity="center" android:id="@+id/tiempo"/>
<TextView android:text="@string/hello_world" android:layout_width="match_parent"
android:layout_height="wrap_content" android:gravity="center" android:id="@+id/velocidad_media"/>
</LinearLayout>
</LinearLayout>
Solution
The problem was that I needed to override this methods of the fragment.
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
Answered By - Juan Manuel Amoros
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.