ऑटोकंप्लीट विजेट के नए वर्शन पर माइग्रेट करना

माइग्रेशन से जुड़ी यह गाइड, उन डेवलपर के लिए है जिन्होंने Place Autocomplete Widget (प्रीव्यू) के साथ, वर्शन 3.59.8 से पहले इंटिग्रेशन किया है. इस गाइड में, आपको नए वर्शन का इस्तेमाल करने के लिए किए जाने वाले बदलावों के बारे में बताया गया है.

बदलाव

  • gmp-placeselect इवेंट का नाम बदलकर gmp-select कर दिया गया है.
  • gmp-select इवेंट अब place इंस्टेंस के बजाय, placePrediction इंस्टेंस दिखाता है. PlacePrediction.toPlace(), सही Place ऑब्जेक्ट दिखाता है.
  • gmp-requesterror इवेंट अब gmp-error है.

माइग्रेट करने का तरीका

Place Autocomplete Widget के इंटिग्रेशन को नए वर्शन पर माइग्रेट करने के लिए, यह तरीका अपनाएं:

  1. पुष्टि करें कि Cloud Console में, आपके प्रोजेक्ट के लिए Places API (नया) चालू हो.
  2. अपनी इस्तेमाल की जा रही एपीआई कुंजी के लिए, Places API (नया) को एपीआई से जुड़ी पाबंदियों की सूची में जोड़ें.
  3. अपने डेवलपमेंट एनवायरमेंट में, ये बदलाव करें और उनकी जांच करें:

इवेंट लिसनर अपडेट करना

यहां दिए गए स्निपेट में दिखाए गए तरीके से, gmp-placeselect को gmp-select में बदलें:

पहले

autocompleteElement.addEventListener('gmp-placeselect', (event) => {
  console.log(event.place);
});

बाद में

autocompleteElement.addEventListener('gmp-select', (event) => {
  console.log(event.placePrediction.toPlace());
});

componentRestrictions को includedRegionCodes में बदलना

यहां दिए गए स्निपेट में दिखाए गए तरीके से, componentRestrictions के इंस्टेंस को बदलकर includedRegionCodes फ़ील्ड का इस्तेमाल करें.

पहले

const autocompleteElement = new google.maps.places.PlaceAutocompleteElement({
  componentRestrictions: {country: ['US']},
  ...
});

बाद में

const autocompleteElement = new google.maps.places.PlaceAutocompleteElement({
  includedRegionCodes: ['US'],
  ...

types को includedPrimaryTypes में बदलना

यहां दिए गए स्निपेट में दिखाए गए तरीके से, types के इंस्टेंस को बदलकर includedPrimaryTypes फ़ील्ड का इस्तेमाल करें.

पहले

const autocompleteElement = new google.maps.places.PlaceAutocompleteElement({
  types: ['restaurant'],
});

बाद में

const autocompleteElement = new google.maps.places.PlaceAutocompleteElement({
  includedPrimaryTypes: ['restaurant'],
});

gmp-requesterror को gmp-error में बदलना

यहां दिए गए स्निपेट में दिखाए गए तरीके से, gmp-requesterror के इंस्टेंस को बदलकर gmp-error करें:

पहले

autocompleteElement.addEventListener('gmp-requesterror', (event) => {
  console.log('an error occurred');
});

बाद में

autocompleteElement.addEventListener('gmp-error', (event) => {
  console.log('an error occurred');
});