इस पेज पर, Android के लिए Maps 3D SDK का इस्तेमाल करके, Android ऐप्लिकेशन में सामान्य 3D मैप जोड़ने का तरीका बताया गया है. इस पेज पर दिए गए निर्देशों में यह माना गया है कि आपने सेटअप पेज पर दिए गए चरणों को पहले ही पूरा कर लिया है. साथ ही, आपके पास ये चीज़ें मौजूद हैं:
Maps 3D SDK for Android की सुविधा वाला Google Cloud प्रोजेक्ट
Android के लिए Maps 3D SDK के साथ इस्तेमाल करने के लिए कॉन्फ़िगर किया गया एपीआई पासकोड
Android Studio प्रोजेक्ट, जिसे Android के लिए Maps 3D SDK के साथ इस्तेमाल करने के लिए सेट अप किया गया हो
इन ज़रूरी शर्तों के बारे में ज़्यादा जानने के लिए, सेटअप देखें.
पहला चरण: Map3DView कॉम्पोनेंट जोड़ने के लिए, लेआउट फ़ाइल (activity_main.xml) को अपडेट करना
Map3DView कॉम्पोनेंट, ऐप्लिकेशन में 3D मैप रेंडर करने वाला व्यू है.
यहां दिए गए चरणों में, कॉम्पोनेंट को जोड़ने और मैप की शुरुआती स्थिति को कॉन्फ़िगर करने का तरीका बताया गया है. इसमें कैमरे की पोज़िशन और उससे जुड़े एट्रिब्यूट शामिल हैं:
अपनी मुख्य गतिविधि की लेआउट फ़ाइल खोलें. यह फ़ाइल आम तौर पर app/src/main/res/layout/activity_main.xml पर मौजूद होती है.
यहां दिए गए तरीके से, पहले हिस्से में activity_main.xml फ़ाइल में जोड़े गए Map3DView कॉम्पोनेंट को शुरू किया जाता है. साथ ही, कॉम्पोनेंट के लाइफ़साइकल इवेंट मैनेज किए जाते हैं:
अपनी MainActivity.kt फ़ाइल खोलें. यह फ़ाइल आम तौर पर app/src/main/java/com/example/yourpackagename/MainActivity.kt पर मौजूद होती है.
Android के लिए Maps 3D SDK टूल के लिए ज़रूरी इंपोर्ट जोड़ें:
onCreate तरीके में, setContentView(...) और ViewCompat.setOnApplyWindowInsetsListener ब्लॉक के बाद, map3DView को शुरू करें, इसके onCreate लाइफ़साइकल के तरीके को कॉल करें, और मैप के लिए एसिंक्रोनस तरीके से अनुरोध करें:
onMap3DViewReady वाले तरीके को बदलें. इस कॉलबैक को तब ट्रिगर किया जाता है, जब मैप का इस्तेमाल किया जा सकता है:
overridefunonMap3DViewReady(googleMap3D:GoogleMap3D){// Interact with the googleMap3D object herethis.googleMap3D=googleMap3D// You can now make calls to the googleMap3D object, e.g.,// googleMap3D.cameraController.flyTo(camera { ... })}
अपनी गतिविधि से लाइफ़साइकल इवेंट को Map3DView पर फ़ॉरवर्ड करें. इसके लिए, Map3DView में ये ओवरराइड जोड़ें:MainActivity
ऐप्लिकेशन के लेआउट और गतिविधि को अपडेट करने के बाद, अब ऐप्लिकेशन को बनाया और चलाया जा सकता है. इससे आपको 3D मैप व्यू दिखेगा.
अपने प्रोजेक्ट को Gradle के साथ सिंक करने के लिए, File > Sync Project with Gradle Files चुनें.
अपने ऐप्लिकेशन को किसी एम्युलेटर या फ़िज़िकल डिवाइस पर बनाने और चलाने के लिए, चलाएं > चलाएं को चुनें.
अगर सब कुछ सही तरीके से कॉन्फ़िगर किया गया है, तो आपको अपने ऐप्लिकेशन में 3D मैप दिखेगा. यह मैप, activity_main.xml में दिए गए निर्देशांकों के आस-पास दिखेगा.
अगले चरण
अब आपने अपने ऐप्लिकेशन में बुनियादी 3D मैप जोड़ लिया है. इसलिए, Android के लिए Maps 3D SDK की ज़्यादा बेहतर सुविधाओं का इस्तेमाल किया जा सकता है. जैसे, कैमरे के पाथ के ऐनिमेशन, 3D मार्कर या पॉलीगॉन.
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-08-17 (UTC) को अपडेट किया गया."],[],[],null,["\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\u003cbr /\u003e\n\nSelect platform: [Android](/maps/documentation/maps-3d/android-sdk/add-a-3d-map \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/add-a-3d-map \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/3d/get-started \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nThis page walks through an example of how to add a basic 3D map to an Android\napp using the Maps 3D SDK for Android. The instructions on this page assume that you\nhave already completed the steps in the\n[Setup](/maps/documentation/maps-3d/android-sdk/setup) page and have the\nfollowing:\n\n- A Google Cloud project with the Maps 3D SDK for Android enabled\n- An API key configured to use with the Maps 3D SDK for Android\n- An Android Studio project set up to use with the Maps 3D SDK for Android\n\nFor more information about these prerequisites, see\n[Setup](/maps/documentation/maps-3d/android-sdk/setup).\n\nPart 1: Update Layout File (`activity_main.xml`) to add the `Map3DView` component\n\nThe `Map3DView` component is the view that renders the 3D map within the app.\nThe following steps add the component and configure the initial state of the\nmap, including the camera position and related attributes:\n| **Note:** The steps in this section assume that you have created and configured your Android Studio project using the process described in [Setup](/maps/documentation/maps-3d/android-sdk/setup), or that you have added a new View activity to an existing project. If you create a new Android Studio project without adding a View activity, your project won't contain an `activity_main.xml` file.\n\n1. Open your main activity's layout file, which is usually located at\n `app/src/main/res/layout/activity_main.xml`.\n\n2. In the root `ConstraintLayout` (or your root layout element), add the `map3d`\n XML namespace:\n\n xmlns:map3d=\"http://schemas.android.com/apk/res-auto\"\n\n3. Delete the default `\u003cTextView\u003e` that displays \"Hello World!\".\n\n4. Add the `Map3DView` component to your layout. You can customize the camera\n position and other attributes:\n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003candroidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n xmlns:map3d=\"http://schemas.android.com/apk/res-auto\" xmlns:tools=\"http://schemas.android.com/tools\"\n android:id=\"@+id/main\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n tools:context=\".MainActivity\"\u003e\n\n \u003ccom.google.android.gms.maps3d.Map3DView\n android:id=\"@+id/map3dView\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n map3d:mode=\"hybrid\"\n map3d:centerLat=\"38.544012\"\n map3d:centerLng=\"-107.670428\"\n map3d:centerAlt=\"2427.6\"\n map3d:heading=\"310\"\n map3d:tilt=\"63\"\n map3d:range=\"8266\"\n map3d:roll=\"0\"\n map3d:minAltitude=\"0\"\n map3d:maxAltitude=\"1000000\"\n map3d:minHeading=\"0\"\n map3d:maxHeading=\"360\"\n map3d:minTilt=\"0\"\n map3d:maxTilt=\"90\"\n app:layout_constraintBottom_toBottomOf=\"parent\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toTopOf=\"parent\" /\u003e\n \u003c/androidx.constraintlayout.widget.ConstraintLayout\u003e\n\nPart 2: Update MainActivity.kt\n\nThe following steps initialize the `Map3DView` component added to the\n`activity_main.xml` file in Part 1 and manage component lifecycle events:\n\n1. Open your `MainActivity.kt` file, which is usually located at\n `app/src/main/java/com/example/yourpackagename/MainActivity.kt`.\n\n2. Add the necessary imports for the Maps 3D SDK for Android:\n\n import com.google.android.gms.maps3d.GoogleMap3D\n import com.google.android.gms.maps3d.Map3DView\n import com.google.android.gms.maps3d.OnMap3DViewReadyCallback\n\n3. Modify the `MainActivity` class to implement `OnMap3DViewReadyCallback`:\n\n class MainActivity : AppCompatActivity(), OnMap3DViewReadyCallback {\n\n4. Declare variables for `Map3DView` and `GoogleMap3D`:\n\n private lateinit var map3DView: Map3DView\n private var googleMap3D: GoogleMap3D? = null\n\n5. In the `onCreate` method, after `setContentView(...)` and the\n `ViewCompat.setOnApplyWindowInsetsListener` block, initialize the `map3DView`,\n call its `onCreate` lifecycle method, and request the map asynchronously:\n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n enableEdgeToEdge()\n setContentView(R.layout.activity_main)\n ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -\u003e\n val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())\n v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)\n insets\n }\n\n map3DView = findViewById(R.id.map3dView)\n map3DView.onCreate(savedInstanceState)\n map3DView.getMap3DViewAsync(this)\n }\n\n6. Override the `onMap3DViewReady` method. This callback is triggered when the\n map is ready to be used:\n\n override fun onMap3DViewReady(googleMap3D: GoogleMap3D) {\n // Interact with the googleMap3D object here\n this.googleMap3D = googleMap3D\n // You can now make calls to the googleMap3D object, e.g.,\n // googleMap3D.cameraController.flyTo(camera { ... })\n }\n\n7. Forward lifecycle events from your Activity to the `Map3DView` by adding the\n following overrides to the `MainActivity`:\n\n override fun onStart() {\n super.onStart()\n map3DView.onStart()\n }\n\n override fun onResume() {\n super.onResume()\n map3DView.onResume()\n }\n\n override fun onPause() {\n map3DView.onPause()\n super.onPause()\n }\n\n override fun onStop() {\n map3DView.onStop()\n super.onStop()\n }\n\n override fun onDestroy() {\n map3DView.onDestroy()\n super.onDestroy()\n }\n\n override fun onSaveInstanceState(outState: Bundle) {\n super.onSaveInstanceState(outState)\n map3DView.onSaveInstanceState(outState)\n }\n\n override fun onLowMemory() {\n super.onLowMemory()\n map3DView.onLowMemory()\n }\n\nPart 3: Sync Gradle and Run\n\nNow that you've updated your app's layout and activity, you can build and run\nthe app to see the 3D map view.\n\n1. To sync your project with Gradle, select **File \\\u003e Sync Project with Gradle Files.**\n\n2. To build and run your app on an emulator or a physical device, select\n **Run \\\u003e Run**.\n\nIf everything is configured correctly, you should see a 3D map displayed in your\napp, centered near the coordinates specified in your `activity_main.xml`.\n\nNext steps\n\nNow that you've added a basic 3D map to your app, you can explore more advanced\nfeatures of the Maps 3D SDK for Android, such as\n[camera path animations](/maps/documentation/maps-3d/android-sdk/custom-camera-paths),\n[3D markers](/maps/documentation/maps-3d/android-sdk/add-a-marker), or\n[polygons](/maps/documentation/maps-3d/android-sdk/add-polygons)."]]