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

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

ऑब्जेक्ट प्लेसमेंट करें

Place ऑब्जेक्ट में किसी जगह के बारे में जानकारी होती है. इसे टेक्स्ट से खोजने, आस-पास खोजने, और जगह के नाम अपने-आप पूरे होने की सुविधा के ज़रिए डाइनैमिक तरीके से दिखाया जाता है. जगह के आईडी या संसाधन के नाम (संसाधन का नाम, जगह के आईडी से पहले places/ लगाकर बनाया जाता है) से भी Place ऑब्जेक्ट बनाया जा सकता है. यहां दिए गए स्निपेट में, जगह के आईडी का इस्तेमाल करके Place ऑब्जेक्ट बनाने का तरीका दिखाया गया है:

// Use a place ID to create a new Place instance.
const place = new Place({
    id: 'ChIJyYB_SZVU2YARR-I1Jjf08F0', // San Diego Zoo
});

जगह के संसाधन के नाम से भी Place ऑब्जेक्ट बनाया जा सकता है:

// Use a place resource name to create a new Place instance.
const place = new Place({
  resourceName: 'places/ChIJyYB_SZVU2YARR-I1JRF08F0', // San Diego Zoo
});

ज़्यादा जानकारी के लिए, PlaceOptions देखें.

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

अगर आपके पास कोई मौजूदा 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: 'ChIJyYB_SZVU2YARR-I1Jjf08F0', // San Diego Zoo
    });

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

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

    // Assemble the info window content.
    const content = document.createElement('div');
    const address = document.createElement('div');
    const placeId = document.createElement('div');
    address.textContent = place.formattedAddress || '';
    placeId.textContent = place.id;
    content.append(placeId, address);

    if (place.googleMapsURI) {
        const link = document.createElement('a');
        link.href = place.googleMapsURI;
        link.target = '_blank';
        link.textContent = 'View Details on Google Maps';
        content.appendChild(link);
    }

    // Display an info window.
    infoWindow.setHeaderContent(place.displayName);
    infoWindow.setContent(content);
    infoWindow.open({
        anchor: marker,
    });
}

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: 'ChIJyYB_SZVU2YARR-I1Jjf08F0', // San Diego Zoo
    });
    // Call fetchFields, passing the desired data fields.
    await place.fetchFields({
        fields: [
            'displayName',
            'formattedAddress',
            'location',
            'googleMapsURI',
        ],
    });
    // Add an Advanced Marker
    const marker = new AdvancedMarkerElement({
        map: innerMap,
        position: place.location,
        title: place.displayName,
    });
    // Assemble the info window content.
    const content = document.createElement('div');
    const address = document.createElement('div');
    const placeId = document.createElement('div');
    address.textContent = place.formattedAddress || '';
    placeId.textContent = place.id;
    content.append(placeId, address);
    if (place.googleMapsURI) {
        const link = document.createElement('a');
        link.href = place.googleMapsURI;
        link.target = '_blank';
        link.textContent = 'View Details on Google Maps';
        content.appendChild(link);
    }
    // Display an info window.
    infoWindow.setHeaderContent(place.displayName);
    infoWindow.setContent(content);
    infoWindow.open({
        anchor: marker,
    });
}
ध्यान दें कि इस फ़ंक्शन से पहले Map और Place को तय किया गया है:
const { Map } = await google.maps.importLibrary("maps");
const { Place } = await google.maps.importLibrary("places");
पूरा उदाहरण देखें