פרטי מקום (חדש)

בחירת פלטפורמה: Android iOS JavaScript Web Service
מפתחים באזור הכלכלי האירופי (EEA)

אחזור שדות

אם יש לכם אובייקט Place או מזהה מקום קיים, תוכלו להשתמש בשיטה Place.fetchFields() כדי לקבל פרטים על המקום הזה. מזינים רשימה של שדות נתוני מקומות שרוצים לקבל, מופרדים בפסיקים. צריך לציין את שמות השדות ב-CamelCase. משתמשים באובייקט Place שמוחזר כדי לקבל נתונים עבור השדות המבוקשים.

בדוגמה הבאה נעשה שימוש במזהה מקום כדי ליצור Place חדש, מתבצעת קריאה ל-Place.fetchFields() כדי לבקש את השדות displayName ו-formattedAddress, נוסף סמן למפה ומתבצע רישום של נתונים מסוימים במסוף.

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");
לדוגמה המלאה