जगह की जानकारी (नई)

प्लैटफ़ॉर्म चुनें: Android iOS JavaScript वेब सेवा
यूरोपियन इकनॉमिक एरिया (ईईए) के डेवलपर

फ़ील्ड फ़ेच करना

अगर आपके पास कोई मौजूदा Place ऑब्जेक्ट या जगह का आईडी है, तो उस जगह के बारे में जानकारी पाने के लिए, Place.fetchFields() तरीके का इस्तेमाल करें. वापस पाने के लिए, जगह के डेटा फ़ील्ड की कॉमा लगाकर अलग की गई सूची दें; फ़ील्ड के नाम कैमल केस में डालें. अनुरोध किए गए फ़ील्ड का डेटा पाने के लिए, दिखाए गए Place ऑब्जेक्ट का इस्तेमाल करें.

यहां दिए गए उदाहरण में, जगह के आईडी का इस्तेमाल करके नया Place बनाया गया है. साथ ही, displayName और formattedAddress फ़ील्ड का अनुरोध करने के लिए, Place.fetchFields() को कॉल किया गया है. इसके अलावा, मैप में मार्कर जोड़ा गया है और कुछ डेटा को कंसोल में लॉग किया गया है.

TypeScript

async function getPlaceDetails() {
    const { Place } =  await google.maps.importLibrary("places") as google.maps.PlacesLibrary;
    const { AdvancedMarkerElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
    // Use place ID to create a new Place instance.
    const place = new Place({
        id: 'ChIJN5Nz71W3j4ARhx5bwpTQEGg',
        requestedLanguage: 'en', // optional
    });

    // Call fetchFields, passing the desired data fields.
    await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location'] });

    // Log the result
    console.log(place.displayName);
    console.log(place.formattedAddress);

    // Add an Advanced Marker
    const marker = new AdvancedMarkerElement({
        map,
        position: place.location,
        title: place.displayName,
    });
}

JavaScript

async function getPlaceDetails() {
    const { Place } = await google.maps.importLibrary("places");
    const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");
    // Use place ID to create a new Place instance.
    const place = new Place({
        id: 'ChIJN5Nz71W3j4ARhx5bwpTQEGg',
        requestedLanguage: 'en', // optional
    });
    // Call fetchFields, passing the desired data fields.
    await place.fetchFields({ fields: ['displayName', 'formattedAddress', 'location'] });
    // Log the result
    console.log(place.displayName);
    console.log(place.formattedAddress);
    // Add an Advanced Marker
    const marker = new AdvancedMarkerElement({
        map,
        position: place.location,
        title: place.displayName,
    });
}
ध्यान दें कि Map और Place को इस फ़ंक्शन से पहले ही तय कर दिया गया है:
const { Map } = await google.maps.importLibrary("maps");
const { Place } = await google.maps.importLibrary("places");
पूरा उदाहरण देखें