Aggiungere un modello 3D a una mappa
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Seleziona la piattaforma:
Android
iOS
JavaScript
Puoi aggiungere un modello 3D importato a una mappa 3D.
Il seguente esempio di codice mostra come aggiungere un modello 3D e posizionarlo nello spazio 3D utilizzando lo struct Model
.
Swift
struct SimpleModelDemo: View {
@State var camera: Camera = .init(latitude: 37.791376, longitude: -122.397571, altitude: 240, heading: 288.0, tilt: 88.0, roll: 0.0, range: 1500)
@State var balloonModel: Model = .init(
position: .init(
latitude: 37.791376,
longitude: -122.397571,
altitude: 200.0),
url: URL(string: "") ?? URL(fileURLWithPath: fileUrl),
altitudeMode: .relativeToMesh,
scale: .init(x: 5, y: 5, z: 5),
orientation: .init(heading: 0, tilt: 0, roll: 0)
)
var body: some View {
Map(camera: $camera, mode: .satellite) {
balloonModel
}
}
}
private let fileUrl = Bundle.main.url(forResource: "balloon", withExtension: "glb")!.path
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-31 UTC.
[null,null,["Ultimo aggiornamento 2025-08-31 UTC."],[],[],null,["# Add a 3D model to a map\n\nSelect platform: [Android](/maps/documentation/maps-3d/android-sdk/add-3d-models \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/add-3d-models \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/3d/models \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\n| This product or feature is Experimental (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google\n| Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage descriptions](/maps/launch-stages).\n\n\nYou can add your own imported 3D model to a 3D map.\n\nThe following code sample demonstrates how to add a 3D model and position it in 3D space using the [`Model` struct](/maps/documentation/maps-3d/ios-sdk/reference/Structs/Model). \n\n### Swift\n\n```swift\nstruct SimpleModelDemo: View {\n @State var camera: Camera = .init(latitude: 37.791376, longitude: -122.397571, altitude: 240, heading: 288.0, tilt: 88.0, roll: 0.0, range: 1500)\n @State var balloonModel: Model = .init(\n position: .init(\n latitude: 37.791376,\n longitude: -122.397571,\n altitude: 200.0),\n url: URL(string: \"\") ?? URL(fileURLWithPath: fileUrl),\n altitudeMode: .relativeToMesh,\n scale: .init(x: 5, y: 5, z: 5),\n orientation: .init(heading: 0, tilt: 0, roll: 0)\n )\n var body: some View {\n Map(camera: $camera, mode: .satellite) {\n balloonModel\n }\n }\n}\nprivate let fileUrl = Bundle.main.url(forResource: \"balloon\", withExtension: \"glb\")!.path\n\n \n```"]]