【问题标题】:Create MapView Programmatically in Android MapsV2在 Android MapsV2 中以编程方式创建 MapView
【发布时间】:2014-08-11 10:00:36
【问题描述】:

Android:创建地图时 我得到了空白页面。我也有一个有效的 API 密钥并将其设置在清单中。 我的活动。

        relativeLayout = new RelativeLayout(context);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        relativeLayout.setLayoutParams(layoutParams);
        GoogleMapOptions googleMapOptions = new GoogleMapOptions();
        googleMapOptions.mapType(GoogleMap.MAP_TYPE_NORMAL)
                .compassEnabled(false).rotateGesturesEnabled(false)
                .tiltGesturesEnabled(false);

        googleMapOptions.camera(new CameraPosition(new LatLng(0, 0), 3, 0,
                0));
        mapView = new MapView(context, googleMapOptions);


        mapView.onCreate(new Bundle());
        relativeLayout.addView(mapView);

        Double[][] latlang = mapData.getLatlang();

        marker = new Marker[mapData.getLatlang().length];
        for (int i = 0; i < mapData.getLatlang().length; i++) {
            this.marker[i] = mapView.getMap()
                    .addMarker(
                            new MarkerOptions()
                                    .position(
                                            new LatLng(latlang[i][0],
                                                    latlang[i][1]))
                                    .title(" ")
                                    .snippet(" "));
        }

【问题讨论】:

    标签: android google-maps-api-3 android-maps-v2


    【解决方案1】:

    我遇到了同样的问题,因为我在 Fragment 中创建 MapView 并忘记将 onResume 方法添加到片段代码中。

            mapView map = new MapView(getActivity(), options));
            map.setClickable(true);
            map.onCreate(savedInstanceState);
            map.onResume();
    

    希望这对某人有所帮助

    【讨论】:

      【解决方案2】:

      在此行后添加setContentView(relativeLayout); relativeLayout.addView(mapView); 它将解决您的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-02
        • 2015-10-26
        • 2021-05-31
        相关资源
        最近更新 更多