【发布时间】:2015-08-08 12:40:52
【问题描述】:
我正在尝试在我的支持片段中设置谷歌地图,但地图没有被加载,我所拥有的只是谷歌地图显示的默认网格。我将它设置在一个 Activity 中并且一切正常,这就是我认为问题在于我在 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;
}
}
这里是 .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>
【问题讨论】:
标签: android maps fragment android-mapview