MapView sch_map = (MapView) dialog.findViewById(R.id.schedule_map);
            sch_map.onCreate(savedInstanceState);

            sch_map.getMapAsync(new OnMapReadyCallback() {
                @Override
                public void onMapReady(final GoogleMap googleMap) {
                    LatLng sydney = new LatLng(-33.867, 151.206);
                    googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
                }
            });

我正在加载对话框内的地图这是由于地图视图是非常缓慢的地图加载,但花了很多时间这是我的布局,我在其中定义地图视图。
<com.google.android.gms.maps.MapView
    android:layout_width="match_parent"
    android:layout_height="300dp"
    map:uiRotateGestures="true"
    map:uiScrollGestures="true"
    map:uiTiltGestures="true"
    map:uiZoomControls="true"
    map:uiZoomGestures="true"
    map:liteMode="true"
    android:id="@+id/schedule_map" />

最佳答案

1)创建一个自定义dialogmap.xml

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <com.google.android.gms.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        style="@style/MyMaterialTheme.Base">

    </com.google.android.gms.maps.MapView>
</RelativeLayout>

2)在Java中定义.xml文件
如果要打开对话框,请单击按钮。所以写下下面的代码在按钮点击事件。
 Dialog dialog = new Dialog(getActivity());
 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
 dialog.setContentView(R.layout.dialogmap);
 dialog.show();
 GoogleMap googleMap;


 MapView mMapView = (MapView) dialog.findViewById(R.id.mapView);
 MapsInitializer.initialize(getActivity());

mMapView = (MapView) dialog.findViewById(R.id.mapView);
mMapView.onCreate(dialog.onSaveInstanceState());
mMapView.onResume();// needed to get the map to display immediately
googleMap = mMapView.getMap();

07-24 09:49
查看更多