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

בחירת פלטפורמה: 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");
לדוגמה המלאה

שימוש ברכיב 'סקירה כללית של מקום'

רכיב סקירת המקום מציג מידע מפורט על מיליוני עסקים, כולל שעות פתיחה, ביקורות עם כוכבים ותמונות, וגם מסלולי הגעה ופעולות אחרות בממשק משתמש מוכן מראש ב-5 גדלים ופורמטים. הוא חלק מספריית הרכיבים המורחבת של Google Maps Platform, שהיא אוסף של רכיבי אינטרנט שעוזרים למפתחים לבנות מפות טובות יותר ותכונות מיקום מהר יותר.

אפשר להשתמש בכלי ההגדרה של Place Overview כדי ליצור קוד להטמעה של רכיב Place Overview בהתאמה אישית, ואז לייצא אותו לשימוש עם מסגרות פופולריות כמו React ו-Angular, או בלי מסגרת בכלל.