Android 选项卡式活动中的映射片段未显示标记?
使用android studio和谷歌地图中的通用选项卡式活动。将显示地图,但不显示标记。我不知道如何解决这个问题,希望可以理解。 参考选项卡:Android 选项卡式活动中的映射片段未显示标记?,android,maps,tabactivity,Android,Maps,Tabactivity,使用android studio和谷歌地图中的通用选项卡式活动。将显示地图,但不显示标记。我不知道如何解决这个问题,希望可以理解。 参考选项卡: else if (getArguments().getInt(ARG_SECTION_NUMBER)==2){ View rootView = inflater.inflate(R.layout.fragment_sub_page2, container, false); return rootView
else if (getArguments().getInt(ARG_SECTION_NUMBER)==2){
View rootView = inflater.inflate(R.layout.fragment_sub_page2, container, false);
return rootView;
}
片段选项卡
public class SubPage2 extends Fragment implements OnMapReadyCallback {
public GoogleMap mMap;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_sub_page2, container,false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
android.app.FragmentManager fragment = getActivity().getFragmentManager();
final MapFragment myMapFragment = (MapFragment) fragment.findFragmentById(R.id.map);
myMapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap=googleMap;
LatLng marker = new LatLng(-33.867, 151.206);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(marker, 13));
mMap.addMarker(new MarkerOptions().title("Hello Google Maps!").position(marker));
}
子页面2布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<fragment android:id="@+id/map"
android:layout_width="wrap_content"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"
>
</fragment>
</FrameLayout>
你的代码看起来不错。只是一种预感,你是否检查过确保你已经尝试了一系列的缩放级别来确定文本是否太小而看不见 您可以使用
mMap.getUiSettings().setZoomControl启用缩放控件(true)代码>
有一种可能性是,标题
可能只控制该标记获得焦点后显示的文本,即单击该标记。为了消除上传空标记的机会,您是否也可以尝试提供BitmapDescriptor
位图描述符示例
// Allocate the MarkerBitmap.
final BitmapDescriptor lMarkerBitmap = BitmapDescriptorFactory.fromResource(R.drawable.my_marker_image);
// Add the Marker.
mMap.addMarker(new MarkerOptions().alpha(1.0f)
.position(marker)
.title("Hello Google Maps!")
.icon(lMarkerBitmap));
只是尝试了一下,没有任何改进。我认为onMapReady甚至没有被执行。我刚刚在我的地图上尝试了你的代码,它似乎工作正常(没有位图描述符
!)。您是否收到任何异常
s?你能看到地图的地理位置吗?没有任何例外,是的,地图本身出现了,我可以滚动浏览。我确信我使用的api键也是正确的。如果有用的话,我也添加了布局。使用android:layout\u width=“wrap\u content”
看起来有点奇怪,但是如果你仍然可以看到GoogleMap
,那可能不是问题所在。
// Allocate the MarkerBitmap.
final BitmapDescriptor lMarkerBitmap = BitmapDescriptorFactory.fromResource(R.drawable.my_marker_image);
// Add the Marker.
mMap.addMarker(new MarkerOptions().alpha(1.0f)
.position(marker)
.title("Hello Google Maps!")
.icon(lMarkerBitmap));