माइग्रेशन से जुड़ी यह गाइड, उन डेवलपर के लिए है जिन्होंने Place Autocomplete Widget (प्रीव्यू) के साथ, वर्शन 3.59.8 से पहले इंटिग्रेशन किया है. इस गाइड में, आपको नए वर्शन का इस्तेमाल करने के लिए किए जाने वाले बदलावों के बारे में बताया गया है.
बदलाव
gmp-placeselectइवेंट का नाम बदलकरgmp-selectकर दिया गया है.gmp-selectइवेंट अबplaceइंस्टेंस के बजाय,placePredictionइंस्टेंस दिखाता है.PlacePrediction.toPlace(), सहीPlaceऑब्जेक्ट दिखाता है.gmp-requesterrorइवेंट अबgmp-errorहै.
माइग्रेट करने का तरीका
Place Autocomplete Widget के इंटिग्रेशन को नए वर्शन पर माइग्रेट करने के लिए, यह तरीका अपनाएं:
- पुष्टि करें कि Cloud Console में, आपके प्रोजेक्ट के लिए Places API (नया) चालू हो.
- अपनी इस्तेमाल की जा रही एपीआई कुंजी के लिए, Places API (नया) को एपीआई से जुड़ी पाबंदियों की सूची में जोड़ें.
- अपने डेवलपमेंट एनवायरमेंट में, ये बदलाव करें और उनकी जांच करें:
इवेंट लिसनर अपडेट करना
यहां दिए गए स्निपेट में दिखाए गए तरीके से, 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');
});