这是我的布局文件:
我的xml文件包含地图布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment">
</fragment>
</FrameLayout>
My FragmentClass
public class RouteFragment extends Fragment {
GoogleMap map;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.map_layout,container,false);
// Getting reference to SupportMapFragment of the activity_main
SupportMapFragment fm = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
// Getting Map for the SupportMapFragment
map = fm.getMap();
MarkerOptions options = new MarkerOptions();
// Setting the position of the marker
options.position(MainActivity.lng1);
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
map.addMarker(options);
options.position(MainActivity.lng2);
map.addMarker(options);
map.moveCamera(CameraUpdateFactory.newLatLng(MainActivity.lng1));
map.animateCamera(CameraUpdateFactory.zoomTo(8));
if(getArguments().getInt("Driving")==1)
map.addPolyline(MainActivity.lineOptions);
else {
Polyline line = map.addPolyline(new PolylineOptions()
.add(MainActivity.lng1, MainActivity.lng2)
.width(5)
.color(Color.RED));
}
return v;
}
}
以下是例外:
FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
清单文件:
我已经请求了所需的权限,并在应用程序中定义了用于填充地图的用途库。
<uses-library android:name="com.google.android.maps"/>
<permission
android:name="com.city.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.city.permission.MAPS_RECEIVE" />