要在Android Studio中显示自定义地图,可以使用谷歌地图的自定义地图功能。以下是一个示例解决方案,包含代码示例:
implementation 'com.google.android.gms:play-services-maps:17.0.0'
private GoogleMap mMap;
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mMapView = findViewById(R.id.mapView);
    mMapView.onCreate(savedInstanceState);
    mMapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            mMap = googleMap;
            // 自定义地图样式
            mMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(MainActivity.this, R.raw.custom_map_style));
            // 在地图上添加标记
            LatLng location = new LatLng(37.7749, -122.4194);
            mMap.addMarker(new MarkerOptions().position(location).title("San Francisco"));
            // 移动相机视角到指定位置
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 12));
        }
    });
}
@Override
protected void onResume() {
    super.onResume();
    mMapView.onResume();
}
@Override
protected void onPause() {
    super.onPause();
    mMapView.onPause();
}
@Override
protected void onDestroy() {
    super.onDestroy();
    mMapView.onDestroy();
}
@Override
public void onLowMemory() {
    super.onLowMemory();
    mMapView.onLowMemory();
}
{
  "version": "1",
  "settings": {
    "mapType": "normal",
    "cameraZoom": 12,
    "cameraTilt": 0,
    "cameraBearing": 0,
    "cameraTargetLat": 37.7749,
    "cameraTargetLng": -122.4194,
    "minZoom": 0,
    "maxZoom": 20,
    "paddingTop": 0,
    "paddingBottom": 0,
    "paddingLeft": 0,
    "paddingRight": 0,
    "gestureRotate": true,
    "gestureScroll": true,
    "gestureZoom": true,
    "gestureTilt": true,
    "gestureRotateWithTwoFingers": true,
    "gestureScrollWithTwoFingers": true,
    "gestureZoomWithTwoFingers": true,
    "myLocationButtonEnabled": true,
    "indoorLevelPickerEnabled": true,
    "compassEnabled": true,
    "zoomControlsEnabled": true,
    "scrollGesturesEnabledDuringRotateOrZoom": true,
    "liteMode": false,
    "mapToolbarEnabled": true,
    "ambientEnabled": false
  },
  "elements": []
}
在上述代码中,首先初始化MapView并在onCreate方法中调用getMapAsync方法,以便在地图准备就绪时获取GoogleMap对象。然后,通过调用setMapStyle方法,将自定义地图样式应用到地图上。接下来,在地图上添加一个标记,并使用moveCamera方法将相机移动到指定位置。
最后,在Activity或Fragment的生命周期方法中调用MapView的相应方法(如onResume、onPause、onDestroy、onLowMemory),以确保MapView的正确生命周期管理。
请注意,此示例仅演示了如何在Android Studio中显示自定义地图。要显示真实的自定义地图,您需要提供包含地图样式的JSON文件,并在其中定义自定义的地图元素(如地标、道路等)。