डिलीवरी का पता, बिलिंग की जानकारी या इवेंट की जानकारी डालते समय, Place Autocomplete की सुविधा वाले फ़ॉर्म चालू करने से, उपयोगकर्ताओं को पता डालते समय कम कीस्ट्रोक और गलतियां करने में मदद मिलती है. इस ट्यूटोरियल में, Place Autocomplete की सुविधा वाले इनपुट फ़ील्ड को चालू करने का तरीका बताया गया है. साथ ही, इसमें यह भी बताया गया है कि उपयोगकर्ता के चुने गए पते के कॉम्पोनेंट की मदद से, पते के फ़ॉर्म के फ़ील्ड कैसे भरें. इसके अलावा, इसमें चुने गए पते को मैप पर दिखाने का तरीका भी बताया गया है, ताकि उपयोगकर्ता को पते की पुष्टि करने में मदद मिल सके.

वीडियो: Place Autocomplete की मदद से, पते के फ़ॉर्म को बेहतर बनाना
पते के फ़ॉर्म
Android
iOS
वेब
Google Maps Platform, मोबाइल प्लैटफ़ॉर्म और वेब के लिए, Place Autocomplete विजेट उपलब्ध कराता है. विजेट में, खोज के लिए एक डायलॉग बॉक्स दिखता है. इसमें, ऑटोकंप्लीट की सुविधा पहले से मौजूद होती है. इसे जगह के हिसाब से खोज के लिए भी ऑप्टिमाइज़ किया जा सकता है. यह विजेट, पिछली इमेज में दिखाया गया है.
कोड प्राप्त करें
GitHub से, Android के लिए Google Places SDK के डेमो की रिपॉज़िटरी को क्लोन करें या डाउनलोड करें.
गतिविधि का Java वर्शन देखें:
/* * Copyright 2022 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.placesdemo; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.ViewStub; import android.widget.Button; import android.widget.CheckBox; import android.widget.Toast; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import com.example.placesdemo.databinding.AutocompleteAddressActivityBinding; import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.LocationServices; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMapOptions; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MapStyleOptions; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.libraries.places.api.Places; import com.google.android.libraries.places.api.model.AddressComponent; import com.google.android.libraries.places.api.model.AddressComponents; import com.google.android.libraries.places.api.model.Place; import com.google.android.libraries.places.api.model.PlaceTypes; import com.google.android.libraries.places.api.net.PlacesClient; import com.google.android.libraries.places.widget.Autocomplete; import com.google.android.libraries.places.widget.model.AutocompleteActivityMode; import java.util.Arrays; import java.util.List; import static android.Manifest.permission.ACCESS_FINE_LOCATION; import static com.google.maps.android.SphericalUtil.computeDistanceBetween; import androidx.activity.EdgeToEdge; /** * Activity for using Place Autocomplete to assist filling out an address form. */ @SuppressWarnings("FieldCanBeLocal") public class AutocompleteAddressActivity extends AppCompatActivity implements OnMapReadyCallback { private static final String TAG = "ADDRESS_AUTOCOMPLETE"; private static final String MAP_FRAGMENT_TAG = "MAP"; private LatLng coordinates; private boolean checkProximity = false; private SupportMapFragment mapFragment; private GoogleMap map; private Marker marker; private PlacesClient placesClient; private View mapPanel; private LatLng deviceLocation; private static final double acceptedProximity = 150; private AutocompleteAddressActivityBinding binding; View.OnClickListener startAutocompleteIntentListener = view -> { view.setOnClickListener(null); startAutocompleteIntent(); }; private final ActivityResultLauncher<Intent> startAutocomplete = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), result -> { if (result.getResultCode() == Activity.RESULT_OK) { Intent intent = result.getData(); if (intent != null) { Place place = Autocomplete.getPlaceFromIntent(intent); // Write a method to read the address components from the Place // and populate the form with the address components Log.d(TAG, "Place: " + place.getAddressComponents()); fillInAddress(place); } } else if (result.getResultCode() == Activity.RESULT_CANCELED) { // The user canceled the operation. Log.i(TAG, "User canceled autocomplete"); } }); @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent intent) { super.onActivityResult(requestCode, resultCode, intent); binding.autocompleteAddress1.setOnClickListener(startAutocompleteIntentListener); } @Override protected void onCreate(Bundle savedInstanceState) { // Enable edge-to-edge display. This must be called before calling super.onCreate(). EdgeToEdge.enable(this); super.onCreate(savedInstanceState); binding = AutocompleteAddressActivityBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); // Retrieve a PlacesClient (previously initialized - see MainActivity) placesClient = Places.createClient(this); // Attach an Autocomplete intent to the Address 1 EditText field binding.autocompleteAddress1.setOnClickListener(startAutocompleteIntentListener); // Update checkProximity when user checks the checkbox CheckBox checkProximityBox = findViewById(R.id.checkbox_proximity); checkProximityBox.setOnCheckedChangeListener((view, isChecked) -> { // Set the boolean to match user preference for when the Submit button is clicked checkProximity = isChecked; }); // Submit and optionally check proximity Button saveButton = findViewById(R.id.autocomplete_save_button); saveButton.setOnClickListener(v -> saveForm()); // Reset the form Button resetButton = findViewById(R.id.autocomplete_reset_button); resetButton.setOnClickListener(v -> clearForm()); } private void startAutocompleteIntent() { // Set the fields to specify which types of place data to // return after the user has made a selection. List<Place.Field> fields = Arrays.asList(Place.Field.ADDRESS_COMPONENTS, Place.Field.LOCATION, Place.Field.VIEWPORT); // Build the autocomplete intent with field, country, and type filters applied Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.OVERLAY, fields) .setCountries(List.of("US")) .setTypesFilter(List.of("establishment")) .build(this); startAutocomplete.launch(intent); } @Override public void onMapReady(@NonNull GoogleMap googleMap) { map = googleMap; try { // Customise the styling of the base map using a JSON object defined // in a string resource. boolean success = map.setMapStyle( MapStyleOptions.loadRawResourceStyle(this, R.raw.style_json)); if (!success) { Log.e(TAG, "Style parsing failed."); } } catch (Resources.NotFoundException e) { Log.e(TAG, "Can't find style. Error: ", e); } map.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 15f)); marker = map.addMarker(new MarkerOptions().position(coordinates)); } private void fillInAddress(Place place) { AddressComponents components = place.getAddressComponents(); StringBuilder address1 = new StringBuilder(); StringBuilder postcode = new StringBuilder(); // Get each component of the address from the place details, // and then fill-in the corresponding field on the form. // Possible AddressComponent types are documented at https://goo.gle/32SJPM1 if (components != null) { for (AddressComponent component : components.asList()) { String type = component.getTypes().get(0); switch (type) { case "street_number": { address1.insert(0, component.getName()); break; } case "route": { address1.append(" "); address1.append(component.getShortName()); break; } case "postal_code": { postcode.insert(0, component.getName()); break; } case "postal_code_suffix": { postcode.append("-").append(component.getName()); break; } case "locality": binding.autocompleteCity.setText(component.getName()); break; case "administrative_area_level_1": { binding.autocompleteState.setText(component.getShortName()); break; } case "country": binding.autocompleteCountry.setText(component.getName()); break; } } } binding.autocompleteAddress1.setText(address1.toString()); binding.autocompletePostal.setText(postcode.toString()); // After filling the form with address components from the Autocomplete // prediction, set cursor focus on the second address line to encourage // entry of sub-premise information such as apartment, unit, or floor number. binding.autocompleteAddress2.requestFocus(); // Add a map for visual confirmation of the address showMap(place); } private void showMap(Place place) { coordinates = place.getLocation(); // It isn't possible to set a fragment's id programmatically so we set a tag instead and // search for it using that. mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG); // We only create a fragment if it doesn't already exist. if (mapFragment == null) { mapPanel = ((ViewStub) findViewById(R.id.stub_map)).inflate(); GoogleMapOptions mapOptions = new GoogleMapOptions(); mapOptions.mapToolbarEnabled(false); // To programmatically add the map, we first create a SupportMapFragment. mapFragment = SupportMapFragment.newInstance(mapOptions); // Then we add it using a FragmentTransaction. getSupportFragmentManager() .beginTransaction() .add(R.id.confirmation_map, mapFragment, MAP_FRAGMENT_TAG) .commit(); mapFragment.getMapAsync(this); } else { updateMap(coordinates); } } private void updateMap(LatLng latLng) { marker.setPosition(latLng); map.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f)); if (mapPanel.getVisibility() == View.GONE) { mapPanel.setVisibility(View.VISIBLE); } } private void saveForm() { Log.d(TAG, "checkProximity = " + checkProximity); if (checkProximity) { checkLocationPermissions(); } else { Toast.makeText( this, R.string.autocomplete_skipped_message, Toast.LENGTH_SHORT) .show(); } } private void clearForm() { binding.autocompleteAddress1.setText(""); binding.autocompleteAddress2.getText().clear(); binding.autocompleteCity.getText().clear(); binding.autocompleteState.getText().clear(); binding.autocompletePostal.getText().clear(); binding.autocompleteCountry.getText().clear(); if (mapPanel != null) { mapPanel.setVisibility(View.GONE); } binding.autocompleteAddress1.requestFocus(); } // Register the permissions callback, which handles the user's response to the // system permissions dialog. Save the return value, an instance of // ActivityResultLauncher, as an instance variable. private final ActivityResultLauncher<String> requestPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { // Since ACCESS_FINE_LOCATION is the only permission in this sample, // run the location comparison task once permission is granted. // Otherwise, check which permission is granted. getAndCompareLocations(); } else { // Fallback behavior if user denies permission Log.d(TAG, "User denied permission"); } }); private void checkLocationPermissions() { if (ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { getAndCompareLocations(); } else { requestPermissionLauncher.launch( ACCESS_FINE_LOCATION); } } @SuppressLint("MissingPermission") private void getAndCompareLocations() { // TODO: Detect and handle if user has entered or modified the address manually and update // the coordinates variable to the Lat/Lng of the manually entered address. May use // Geocoding API to convert the manually entered address to a Lat/Lng. LatLng enteredLocation = coordinates; map.setMyLocationEnabled(true); FusedLocationProviderClient fusedLocationClient = LocationServices.getFusedLocationProviderClient(this); fusedLocationClient.getLastLocation() .addOnSuccessListener(this, location -> { // Got last known location. In some rare situations this can be null. if (location == null) { return; } deviceLocation = new LatLng(location.getLatitude(), location.getLongitude()); Log.d(TAG, "device location = " + deviceLocation); Log.d(TAG, "entered location = " + enteredLocation.toString()); // Use the computeDistanceBetween function in the Maps SDK for Android Utility Library // to use spherical geometry to compute the distance between two Lat/Lng points. double distanceInMeters = computeDistanceBetween(deviceLocation, enteredLocation); if (distanceInMeters <= acceptedProximity) { Log.d(TAG, "location matched"); // TODO: Display UI based on the locations matching } else { Log.d(TAG, "location not matched"); // TODO: Display UI based on the locations not matching } }); } }
एपीआई चालू करना
इन सुझावों को लागू करने के लिए, आपको Google Cloud Console में ये एपीआई चालू करने होंगे:
- Android के लिए Maps SDK (या आपके चुने गए प्लैटफ़ॉर्म के लिए एपीआई)
- Places API
सेटअप के बारे में ज़्यादा जानने के लिए, Google Cloud प्रोजेक्ट सेट अप करना लेख पढ़ें.
इनपुट फ़ील्ड में ऑटोकंप्लीट की सुविधा जोड़ना
इस सेक्शन में, पते के फ़ॉर्म में Place Autocomplete की सुविधा जोड़ने का तरीका बताया गया है.
Place Autocomplete विजेट जोड़ना
Android में, ऑटोकंप्लीट विजेट को Autocomplete intent का इस्तेमाल करके जोड़ा जा सकता है. इससे, पते की पहली लाइन वाले इनपुट फ़ील्ड से Place Autocomplete की सुविधा लॉन्च होती है. उपयोगकर्ता यहां अपना पता डालना शुरू करेगा. टाइप करना शुरू करने पर, वे ऑटोकंप्लीट के अनुमानों की सूची से अपना पता चुन पाएंगे.
सबसे पहले, गतिविधि लॉन्चर तैयार करें, ActivityResultLauncherका इस्तेमाल करके,
जो लॉन्च की गई गतिविधि से मिलने वाले नतीजे को सुनेगा. नतीजे के कॉलबैक में, Place ऑब्जेक्ट शामिल होगा. यह ऑब्जेक्ट, उस पते से जुड़ा होगा जिसे उपयोगकर्ता ने ऑटोकंप्लीट के अनुमानों में से चुना है.
private final ActivityResultLauncher<Intent> startAutocomplete = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), result -> { if (result.getResultCode() == Activity.RESULT_OK) { Intent intent = result.getData(); if (intent != null) { Place place = Autocomplete.getPlaceFromIntent(intent); // Write a method to read the address components from the Place // and populate the form with the address components Log.d(TAG, "Place: " + place.getAddressComponents()); fillInAddress(place); } } else if (result.getResultCode() == Activity.RESULT_CANCELED) { // The user canceled the operation. Log.i(TAG, "User canceled autocomplete"); } });
इसके बाद,
Place Autocomplete intent के फ़ील्ड, जगह, और टाइप की प्रॉपर्टी तय करें. साथ ही,
Autocomplete.IntentBuilder की मदद से इसे बनाएं.
आखिर में, कोड के पिछले उदाहरण में तय किए गए ActivityResultLauncher का इस्तेमाल करके, intent लॉन्च करें.
private void startAutocompleteIntent() { // Set the fields to specify which types of place data to // return after the user has made a selection. List<Place.Field> fields = Arrays.asList(Place.Field.ADDRESS_COMPONENTS, Place.Field.LOCATION, Place.Field.VIEWPORT); // Build the autocomplete intent with field, country, and type filters applied Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.OVERLAY, fields) .setCountries(List.of("US")) .setTypesFilter(List.of("establishment")) .build(this); startAutocomplete.launch(intent); }
Place Autocomplete से मिले पते को मैनेज करना
ActivityResultLauncher को पहले से तय करने पर, यह भी तय हो जाता है कि कॉलबैक में गतिविधि का नतीजा मिलने पर क्या करना है. अगर उपयोगकर्ता ने कोई अनुमान चुना है, तो यह नतीजे के ऑब्जेक्ट में शामिल intent में डिलीवर किया जाएगा. चूंकि intent को Autocomplete.IntentBuilder ने बनाया है, इसलिए Autocomplete.getPlaceFromIntent() तरीका, उससे Place ऑब्जेक्ट को एक्सट्रैक्ट कर सकता है.
private final ActivityResultLauncher<Intent> startAutocomplete = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), result -> { if (result.getResultCode() == Activity.RESULT_OK) { Intent intent = result.getData(); if (intent != null) { Place place = Autocomplete.getPlaceFromIntent(intent); // Write a method to read the address components from the Place // and populate the form with the address components Log.d(TAG, "Place: " + place.getAddressComponents()); fillInAddress(place); } } else if (result.getResultCode() == Activity.RESULT_CANCELED) { // The user canceled the operation. Log.i(TAG, "User canceled autocomplete"); } });
इसके बाद, Place.getAddressComponents() को कॉल करें और पते के हर कॉम्पोनेंट को, पते के फ़ॉर्म में मौजूद उसके इनपुट फ़ील्ड से मैच करें. साथ ही, उपयोगकर्ता के चुने गए Place की वैल्यू से फ़ील्ड भरें.
पते के फ़ॉर्म के फ़ील्ड भरने के लिए, लागू करने का एक उदाहरण इस पेज के fillInAddress तरीके में दिए गए सैंपल कोड के कोड पाएं सेक्शन में शेयर किया गया है.
मैन्युअल तरीके से डाले गए पते के बजाय, अनुमान से पते का डेटा कैप्चर करने से, पते की सटीक जानकारी मिलती है. साथ ही, यह पक्का होता है कि पता सही है और उस पते पर डिलीवरी की जा सकती है. इसके अलावा, इससे उपयोगकर्ता के कीस्ट्रोक भी कम होते हैं.
Place Autocomplete को लागू करते समय ध्यान देने वाली बातें
Place Autocomplete में कई विकल्प होते हैं. इनकी मदद से, अगर आपको सिर्फ़ विजेट के अलावा अन्य सुविधाओं का इस्तेमाल करना है, तो इसे अपनी ज़रूरत के हिसाब से लागू किया जा सकता है. जगह की जानकारी को सही तरीके से मैच करने के लिए, सेवाओं के कॉम्बिनेशन का इस्तेमाल किया जा सकता है.
पते के फ़ॉर्म के लिए, टाइप पैरामीटर को
addressपर सेट करें, ताकि मैच को सिर्फ़ पूरे पतों तक सीमित किया जा सके. Place Autocomplete के अनुरोधों में इस्तेमाल किए जा सकने वाले टाइप के बारे में ज़्यादा जानें.अगर आपको दुनिया भर में खोज करने की ज़रूरत नहीं है, तो सही पाबंदियां और पूर्वाग्रह सेट करें. ऐसे कई पैरामीटर हैं जिनका इस्तेमाल, किसी भी मैच को सिर्फ़ खास इलाकों तक सीमित करने या पूर्वाग्रह सेट करने के लिए किया जा सकता है.
किसी इलाके के लिए, आयताकार सीमाएं सेट करने के लिए
RectangularBoundsका इस्तेमाल करें. साथ ही, यह पक्का करने के लिएsetLocationRestriction()का इस्तेमाल करें कि सिर्फ़ उन इलाकों के पते दिखाए जाएं.जवाबों को कुछ देशों तक सीमित करने के लिए,
setCountries()का इस्तेमाल करें.
अगर मैच में कुछ फ़ील्ड छूट जाते हैं, तो उन्हें एडिट किया जा सकने वाला बनाएं. साथ ही, अगर ज़रूरत हो, तो ग्राहकों को पता अपडेट करने की अनुमति दें. Place Autocomplete से मिले ज़्यादातर पतों में, अपार्टमेंट, सुइट या यूनिट नंबर जैसे सबप्रिमाइज़ नंबर शामिल नहीं होते. इसलिए, उपयोगकर्ता को यह जानकारी भरने के लिए बढ़ावा देने के लिए, फ़ोकस को पते की दूसरी लाइन पर ले जाया जा सकता है.
पते की पुष्टि करने के लिए विज़ुअल जानकारी देना
पते की जानकारी डालते समय, उपयोगकर्ताओं को मैप पर पते की पुष्टि करने के लिए विज़ुअल जानकारी दें. इससे उपयोगकर्ताओं को यह पक्का करने में मदद मिलती है कि पता सही है.
नीचे दी गई इमेज में, पते के नीचे एक मैप दिखाया गया है. इसमें, डाले गए पते पर पिन लगा है.

यहां दिए गए उदाहरण में, Android में मैप जोड़ने के बुनियादी चरणों के बारे में बताया गया है. ज़्यादा जानकारी के लिए, दस्तावेज़ देखें.
SupportMapFragmentजोड़ना. इस मामले में, डाइनैमिक तरीके से फ़्रैगमेंट जोड़ना- फ़्रैगमेंट का हैंडल पाना और कॉलबैक रजिस्टर करना
- मैप में स्टाइल जोड़ना और मार्कर जोड़ना
- मैप के कंट्रोल बंद करना
SupportMapFragment जोड़ना
सबसे पहले, SupportMapFragment फ़्रैगमेंट को
लेआउट की XML फ़ाइल में जोड़ें.
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/confirmation_map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>इसके बाद, अगर फ़्रैगमेंट पहले से मौजूद नहीं है, तो उसे प्रोग्राम के ज़रिए जोड़ें.
private void showMap(Place place) {
coordinates = place.getLocation();
// It isn't possible to set a fragment's id programmatically so we set a tag instead and
// search for it using that.
mapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG);
// We only create a fragment if it doesn't already exist.
if (mapFragment == null) {
mapPanel = ((ViewStub) findViewById(R.id.stub_map)).inflate();
GoogleMapOptions mapOptions = new GoogleMapOptions();
mapOptions.mapToolbarEnabled(false);
// To programmatically add the map, we first create a SupportMapFragment.
mapFragment = SupportMapFragment.newInstance(mapOptions);
// Then we add it using a FragmentTransaction.
getSupportFragmentManager()
.beginTransaction()
.add(R.id.confirmation_map, mapFragment, MAP_FRAGMENT_TAG)
.commit();
mapFragment.getMapAsync(this);
} else {
updateMap(coordinates);
}
}फ़्रैगमेंट का हैंडल पाना और कॉलबैक रजिस्टर करना
फ़्रैगमेंट का हैंडल पाने के लिए,
FragmentManager.findFragmentByIdतरीके को कॉल करें और उसे अपने लेआउट फ़ाइल में फ़्रैगमेंट का संसाधन आईडी पास करें. अगर आपने फ़्रैगमेंट डाइनैमिक तरीके से जोड़ा है, तो यह चरण छोड़ दें, क्योंकि आपने पहले ही हैंडल पा लिया है.फ़्रैगमेंट पर कॉलबैक सेट करने के लिए,
getMapAsyncतरीके को कॉल करें.
उदाहरण के लिए, अगर आपने फ़्रैगमेंट को स्टैटिक तरीके से जोड़ा है, तो:
Kotlin
val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment mapFragment.getMapAsync(this)
Java
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this);
मैप में स्टाइल जोड़ना और मार्कर जोड़ना
मैप तैयार होने पर, स्टाइल सेट करें, कैमरा को बीच में लाएं, और डाले गए पते के कोऑर्डिनेट पर मार्कर जोड़ें. यहां दिए गए कोड में, JSON ऑब्जेक्ट में तय की गई स्टाइल का इस्तेमाल किया गया है. इसके अलावा, ऐसा मैप आईडी लोड किया जा सकता है जिसे क्लाउड पर मैप की स्टाइलिंग की सुविधाओं का इस्तेमाल करके तय किया गया हो.
@Override public void onMapReady(@NonNull GoogleMap googleMap) { map = googleMap; try { // Customise the styling of the base map using a JSON object defined // in a string resource. boolean success = map.setMapStyle( MapStyleOptions.loadRawResourceStyle(this, R.raw.style_json)); if (!success) { Log.e(TAG, "Style parsing failed."); } } catch (Resources.NotFoundException e) { Log.e(TAG, "Can't find style. Error: ", e); } map.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 15f)); marker = map.addMarker(new MarkerOptions().position(coordinates)); }
मैप के कंट्रोल बंद करना
अगर आपको मैप को आसान बनाना है, ताकि उसमें कंपास, टूलबार या अन्य इन-बिल्ट सुविधाओं जैसे अतिरिक्त मैप कंट्रोल के बिना, सिर्फ़ जगह की जानकारी दिखे, तो उन कंट्रोल को बंद करें जिनकी आपको ज़रूरत नहीं है. Android पर, सीमित इंटरैक्टिविटी देने के लिए, लाइट मोड चालू करने का एक और विकल्प है.