Configurer les restrictions de carte et de caméra

Sélectionnez une plate-forme : Android iOS JavaScript

Vue de carte montrant les restrictions applicables aux commandes de la caméra

L'exemple de code suivant montre comment utiliser CameraRestriction pour limiter à la fois les limites géographiques de la caméra et les valeurs de l'altitude, du cap et de l'inclinaison de la caméra.

// Add imports and define constants
import com.google.android.gms.maps3d.model.AltitudeMode
import com.google.android.gms.maps3d.model.LatLngAltitude
import com.google.android.gms.maps3d.model.cameraRestriction
import com.google.android.gms.maps3d.model.latLngAltitude
import com.google.android.gms.maps3d.model.latLngBounds
import com.google.android.gms.maps3d.model.polygonOptions

const val EMPIRE_STATE_BUILDING_LATITUDE = 40.748233
const val EMPIRE_STATE_BUILDING_LONGITUDE = -73.985663

private const val NYC_SOUTH_WEST_LAT = 40.68563088976172
private const val NYC_SOUTH_WEST_LNG = -74.05030430240065
private const val NYC_NORTH_EAST_LAT = 40.85649214337128
private const val NYC_NORTH_EAST_LNG = -73.80240973771173
private const val MAX_ALTITUDE_NYC_METERS = 10000.0
private const val MIN_ALTITUDE_NYC_METERS = 500.0

private val nycBounds = latLngBounds {
    northEastLat = NYC_NORTH_EAST_LAT
    northEastLng = NYC_NORTH_EAST_LNG
    southWestLat = NYC_SOUTH_WEST_LAT
    southWestLng = NYC_SOUTH_WEST_LNG
}

// Define the restrictions
val nycCameraRestriction = cameraRestriction {
  minAltitude = MIN_ALTITUDE_NYC_METERS
  maxAltitude = MAX_ALTITUDE_NYC_METERS
  minHeading = 0.0
  maxHeading = 360.0
  minTilt = 0.0
  maxTilt = 90.0
  bounds = nycBounds
}