如何给 android 地图框充气?
How to inflate android mapbox?
我在给 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) {
}
});
}
}
两个底部导航项都正常工作
您忘记提及错误,但我认为您的代码可以正常工作。
您尚未定义地图的中心位置,因此它可能会回落到 lat/lng of 0/0。这是对的in the middle of the atlantic ocean。所以你在地图上看到的蓝色只是水:)
尝试移动地图并缩小,您很快就会看到非洲!
编辑
我又看了一遍。你在说这个吗?
Mapbox.getInstance(this, getString(R.string.access_token)); // Error in context:this
好吧,如果此代码在片段中执行,您可能需要 getActivity()
而不仅仅是 this
我在给 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) {
}
});
}
}
两个底部导航项都正常工作
您忘记提及错误,但我认为您的代码可以正常工作。
您尚未定义地图的中心位置,因此它可能会回落到 lat/lng of 0/0。这是对的in the middle of the atlantic ocean。所以你在地图上看到的蓝色只是水:)
尝试移动地图并缩小,您很快就会看到非洲!
编辑
我又看了一遍。你在说这个吗?
Mapbox.getInstance(this, getString(R.string.access_token)); // Error in context:this
好吧,如果此代码在片段中执行,您可能需要 getActivity()
而不仅仅是 this