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

माइग्रेट करने से जुड़ी यह गाइड उन डेवलपर के लिए है जिन्होंने वर्शन 3.59.8 से पहले, किसी जगह के शुरुआती अक्षर लिखने पर पूरा नाम सुझाने की सुविधा वाले विजेट (झलक) को इंटिग्रेट किया है. इस गाइड में बताया गया है कि नए वर्शन का इस्तेमाल करने के लिए, आपको कौनसे बदलाव करने होंगे.

बदलाव

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

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

किसी जगह के शुरुआती अक्षर लिखने पर पूरा नाम सुझाने की सुविधा वाले विजेट के इंटिग्रेशन को नए वर्शन पर माइग्रेट करने के लिए, यह तरीका अपनाएं:

  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');
});