我的应用程序中有两个Google地图,它们的实现方式相同。一种有效,一种无效。后者看起来像图像,我无法与之交互。我可以添加标记并移动相机,但是单击标记后,无法移动,放大和缩小,信息窗口不会显示。它看起来像图像,是预览。

这是代码:

public class MapFragment extends Fragment implements OnMapReadyCallback{

    private GoogleMap mMap;
    private static Double latitude;
    private static Double longitude;
    private static String title;

    public static MapFragment newInstance(Double mLatitude, Double mLongitude, String mTitle) {
        latitude=mLatitude;
        longitude=mLongitude;
        title=mTitle;
        MapFragment fragment = new MapFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_map, container, false);
        SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
                .findFragmentById(R.id.map_details);
        mapFragment.getMapAsync(this);
        return view;
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.getUiSettings().setAllGesturesEnabled(true);
        mMap.getUiSettings().setMapToolbarEnabled(false);
        mMap.addMarker(new MarkerOptions()
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon))
                .position(new LatLng(latitude, longitude))
                .title(title));
        CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(latitude,longitude)).zoom(12f).build();
        CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition);
        mMap.moveCamera(cameraUpdate);
    }

    public interface OnMapFragmentInteractionListener {
        void onMapFragmentInteraction(Uri uri);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }
}

最佳答案

您应该看一下XML。有liteMode,当将其设置为true时,它完全按照您的描述进行操作。

<com.google.android.gms.maps.MapView
            android:id="@+id/row_map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            map:liteMode="true"
            map:mapType="none" />


在这里查看documentation

关于android - Google map 看起来像一张图片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45550748/

10-09 06:40