'জায়গার রিভিউ' আপনাকে ওয়েব পেজে ব্যবহারকারীর রিভিউ ও রেটিং যোগ করতে দেয়। এই পৃষ্ঠা
Place ক্লাস
(নতুন) এবং PlacesService (পুরানো) এ ব্যবহৃত স্থানের পর্যালোচনার মধ্যে পার্থক্য ব্যাখ্যা করে এবং
তুলনার জন্য কিছু কোড স্নিপেট প্রদান করে।
PlacesService(লিগ্যাসি)getDetails()অনুরোধের জন্যPlaceResultঅবজেক্টের অংশ হিসেবেPlaceReviewইনস্ট্যান্সের একটি অ্যারে প্রদান করে যদি অনুরোধেreviewsফিল্ড নির্দিষ্ট করা থাকে।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 ক্লাসে জায়গার রিভিউয়ের মধ্যে পার্থক্য বোঝা যায়।
Places পরিষেবা (পুরনো)
নিম্নলিখিত স্নিপেট 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,
});