প্লেস রিভিউ আপনাকে নিজের ওয়েবপেজে ব্যবহারকারীর রিভিউ ও রেটিং যোগ করতে দেয়। এই পৃষ্ঠা
Place ক্লাস (নতুন) এবং PlacesService (পুরনো)-এ ব্যবহৃত জায়গার রিভিউয়ের মধ্যে পার্থক্য ব্যাখ্যা করে এবং
তুলনা করার জন্য কিছু কোড স্নিপেট প্রদান করে।
PlacesService(legacy)getDetails()অনুরোধেreviewsফিল্ড উল্লেখ করা থাকলে,PlaceResultঅবজেক্টের অংশ হিসেবেPlaceReviewইনস্ট্যান্সের একটি অ্যারে রিটার্ন করে।Place(নতুন)fetchFields()অনুরোধের অংশ হিসেবেReviewইনস্ট্যান্সের একটি অ্যারে রিটার্ন করে যদি অনুরোধেreviewsফিল্ড নির্দিষ্ট করা থাকে।
Place ক্লাস ও PlacesService-এর মধ্যে জায়গা
পর্যালোচনা ব্যবহারের কিছু প্রধান পার্থক্য নিচে দেওয়া হল:
PlacesService (লিগ্যাসি) |
Place (নতুন) |
|---|---|
PlaceReview ইন্টারফেস |
Review ক্লাস |
ফলাফল অবজেক্ট এবং উত্তর ম্যানেজ করার জন্য
google.maps.places.PlacesServiceStatus পদ্ধতিতে কলব্যাক ব্যবহার করতে হয়। |
Promises ব্যবহার করে এবং অ্যাসিঙ্ক্রোনাসভাবে কাজ করে। |
পদ্ধতিগুলির জন্য PlacesServiceStatus চেক প্রয়োজন। |
স্ট্যাটাস চেক করার প্রয়োজন নেই, স্ট্যান্ডার্ড এরর হ্যান্ডলিং ব্যবহার করতে পারেন। আরও জানুন। |
PlacesService অবশ্যই কোনও ম্যাপ বা
div এলিমেন্ট ব্যবহার করে ইনস্ট্যানশিয়েট করতে হবে। |
ম্যাপ বা পৃষ্ঠা এলিমেন্টের রেফারেন্স ছাড়াই, যেখানে প্রয়োজন সেখানে Place ইনস্ট্যান্টিয়েট করা
যেতে পারে। |
PlaceReview, author_name, author_url এবং
profile_photo_url ফিল্ড ব্যবহার করে
রিভিউয়ের জন্য অ্যাট্রিবিউশন ডেটা রিটার্ন করে। |
Review,
AuthorAttribution ইনস্ট্যান্স ব্যবহার করে
রিভিউয়ের জন্য অ্যাট্রিবিউশন ডেটা রিটার্ন করে। |
কোডের তুলনা
এই বিভাগে, লেগাসি PlacesService এবং নতুন Place ক্লাসের মধ্যে পার্থক্য
বোঝাতে টেক্সট সার্চ পদ্ধতির কোডের তুলনা করা হয়েছে।
প্লেসেস পরিষেবা (লিগ্যাসি)
নিম্নলিখিত স্নিপেটটি getDetails()-কে কল করে, যার মধ্যে
পর্যালোচনা সহ জায়গার বিবরণ অনুরোধ করে এবং একটি ইনফো উইন্ডোতে প্রথম পর্যালোচনার ফলাফল দেখায়।
const request = {
placeId: "ChIJpyiwa4Zw44kRBQSGWKv4wgA", // Faneuil Hall Marketplace, Boston, MA
fields: ["name", "formatted_address", "geometry", "reviews"],
};
const service = new google.maps.places.PlacesService(map);
service.getDetails(request, (place, status) => {
if (
status === google.maps.places.PlacesServiceStatus.OK &&
place &&
place.geometry &&
place.geometry.location
) {
// If there are any reviews display the first one.
if (place.reviews && place.reviews.length > 0) {
// Get info for the first review.
let reviewRating = place.reviews[0].rating;
let reviewText = place.reviews[0].text;
let authorName = place.reviews[0].author_name;
let authorUri = place.reviews[0].author_url;
// Format the review using HTML.
contentString =`
<div id="title"><b>${place.name}</b></div>
<div id="address">${place.formatted_address}</div>
<a href="${authorUri}" target="_blank">Author: ${authorName}</a>
<div id="rating">Rating: ${reviewRating} stars</div>
<div id="rating"><p>Review: ${reviewText}</p></div>`;
} else {
contentString = `No reviews were found for ${place.name}`;
}
const infowindow = new google.maps.InfoWindow({
content: contentString,
ariaLabel: place.displayName,
});
// Add a marker.
const marker = new google.maps.Marker({
map,
position: place.geometry.location,
});
// Show the info window.
infowindow.open({
anchor: marker,
map,
});
}
});
প্লেস ক্লাস (নতুন)
নিম্নলিখিত স্নিপেট fetchFields()
মেথড কল করে রিভিউ সহ জায়গার বিবরণ অনুরোধ করে এবং প্রথম রিভিউয়ের ফলাফল
ইনফো উইন্ডোতে দেখায়।
// Use a place ID to create a new Place instance.
const place = new google.maps.places.Place({
id: "ChIJpyiwa4Zw44kRBQSGWKv4wgA", // Faneuil Hall Marketplace, Boston, MA
});
// Call fetchFields, passing 'reviews' and other needed fields.
await place.fetchFields({
fields: ["displayName", "formattedAddress", "location", "reviews"],
});
// If there are any reviews display the first one.
if (place.reviews && place.reviews.length > 0) {
// Get info for the first review.
let reviewRating = place.reviews[0].rating;
let reviewText = place.reviews[0].text;
let authorName = place.reviews[0].authorAttribution.displayName;
let authorUri = place.reviews[0].authorAttribution.uri;
// Format the review using HTML.
contentString =`
<div id="title"><b>${place.displayName}</b></div>
<div id="address">${place.formattedAddress}</div>
<a href="${authorUri}" target="_blank">Author: ${authorName}</a>
<div id="rating">Rating: ${reviewRating} stars</div>
<div id="rating"><p>Review: ${reviewText}</p></div>`;
} else {
contentString = `No reviews were found for ${place.displayName}`;
}
// Create an infowindow to display the review.
infoWindow = new google.maps.InfoWindow({
content: contentString,
ariaLabel: place.displayName,
});
// Add a marker.
const marker = new google.maps.marker.AdvancedMarkerElement({
map,
position: place.location,
title: place.displayName,
});
// Show the info window.
infoWindow.open({
anchor: marker,
map,
});