【发布时间】:2020-01-10 13:20:46
【问题描述】:
我无法为 mapbox 充气。我尝试将 getInstance 放在 MainActivity 上,片段在最左下角加载了 mapbox 徽标,但地图为空。所以我尝试将 getInstance 放在片段上,然后我得到了错误。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_map, container, false);
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.access_token)); // Error in context:this
mapView = view.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
return view;
}
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
}
});
}
}
两个底部导航项都在工作
【问题讨论】:
标签: android android-layout android-fragments mapbox mapbox-android