স্থানের বিবরণ (নতুন)

ইউরোপীয় অর্থনৈতিক অঞ্চল (EEA) ডেভেলপাররা

বস্তু স্থাপন করুন

Place অবজেক্ট, যা একটি স্থান সম্পর্কে তথ্য ধারণ করে, তা টেক্সট সার্চ, নিয়ারবাই সার্চ এবং প্লেস অটোকমপ্লিট দ্বারা ডাইনামিকভাবে ফেরত আসে। আপনি একটি প্লেস আইডি বা রিসোর্স নেম থেকেও একটি Place অবজেক্ট তৈরি করতে পারেন (রিসোর্স নেম হলো প্লেস আইডির আগে places/ যুক্ত করা)। নিচের কোড স্নিপেটটি একটি প্লেস আইডি ব্যবহার করে 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() কল করে এবং ম্যাপে একটি মার্কার যোগ করে।

টাইপস্ক্রিপ্ট

async function getPlaceDetails() {
    const [{ Place }, { AdvancedMarkerElement }] = await Promise.all([
        google.maps.importLibrary('places'),
        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,
    });
}

জাভাস্ক্রিপ্ট

async function getPlaceDetails() {
    const [{ Place }, { AdvancedMarkerElement }] = await Promise.all([
        google.maps.importLibrary('places'),
        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");
সম্পূর্ণ উদাহরণটি দেখুন