我把mapbox放在片段中,但我只能看到标题。这是片段中的代码。
我只能看到带有mapbox标题的灰色屏幕。除了模拟器,我没有错误。此外,我试图在父活动中获取MapBox的实例,但它也不起作用。我当然可以使用一些帮助。
public class MapBox extends Fragment
{
View root;
MapView mapView;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Mapbox.getInstance(getContext(),
"pk.eyJ1IjoiYWNpaGFuayIsImEiOiJjamRobGVpdjUwd2tpMndtZmpsemxybjBjIn0.dmYB5bqnEqC57WqfH06hIQ");
root = inflater.inflate(R.layout.mapbox_layout, container, false);
return root;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
mapView =(MapView) (root).findViewById(R.id.mapboxView);
mapView.onCreate(savedInstanceState);
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
}
答案 0 :(得分:0)
您是否设置了互联网,精确位置和访问WiFi状态的权限,如下所示:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
并设置ACCESS_WIFI_STATE
。您也可以不使用onViewCreated
- 方法执行此操作,并将其全部放在onCreateView
- 方法中。
MapBox还在github上有一个演示。愿这会帮助你。