【问题标题】:GoogleMap loads only at alternative attempts androidGoogleMap 仅在替代尝试时加载 android
【发布时间】:2015-03-10 22:07:16
【问题描述】:

我的项目有 导航抽屉,在第一次实例化 googleMap 片段时工作正常,即显示带有标记的 googleMap,然后从导航抽屉中选择另一个片段,然后尝试返回 googleMap地图不加载的片段。为什么会这样?

这是我的代码:

public class Contact_Us extends Fragment {

    static final LatLng Annr = new LatLng(13.0846, 80.2179);
    // static final LatLng KIEL = new LatLng(53.551, 9.993);
    private GoogleMap map;
    private static View mView;
    SupportMapFragment mMapFragment = SupportMapFragment.newInstance();

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (mView != null) {
            ((ViewGroup) mView.getParent()).removeAllViews();
        }
        mView = inflater.inflate(R.layout.contact_us, null);
        if (map == null) {
            FragmentTransaction fragmentTransaction = getChildFragmentManager()
                    .beginTransaction();
            fragmentTransaction.add(R.id.map, mMapFragment);
            fragmentTransaction.commit();
        }
        return mView;
    }

    @Override
    public void onStart() {
        // TODO Auto-generated method stub
        map = mMapFragment.getMap();
        if (map != null) {
            map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            map.getUiSettings().setMyLocationButtonEnabled(false);
            map.setMyLocationEnabled(true);

            Marker hamburg12 = map.addMarker(new MarkerOptions().position(
                    AnnaNagar).title("Reality Today"));
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(Annr , 15));
            map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
        }
        super.onStart();
    }
}

也尝试过这个解决方案mapFragment.getMap() returns null>

有什么问题?

谢谢,

【问题讨论】:

    标签: android android-fragments google-maps-android-api-2


    【解决方案1】:

    getMap 已弃用,更改为 getMapAsync 并判断它是否有帮助。

    【讨论】:

    • 用更改的代码编辑问题并发布 logcat 输出
    猜你喜欢
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多