2 回答
TA贡献1777条经验 获得超10个赞
在您的片段中使用 MapView:
<RelativeLayout 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"
tools:context=".HomeFragment">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/llSelectDetails" />
</RelativeLayout>
在您的片段中使用:
public class HomeFragment extends Fragment implements OnMapReadyCallback {
private GoogleMap mMap;
private MapView mMapView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_home, container, false)
/*
* Configure Mapview and sync to google map.
*/
mMapView = rootView.findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(this);
mMapView.onResume(); // needed to get the map to display immediately
//your code
return rootView;
}
@Override
public void onMapReady(GoogleMap googleMap) {
this.mMap = googleMap;
}
}
它会工作得很好。另外,请检查您的地图密钥和互联网连接。
添加回答
举报