নতুন কাছাকাছি অনুসন্ধানে স্থানান্তর করুন,নতুন কাছাকাছি অনুসন্ধানে স্থানান্তর করুন,নতুন কাছাকাছি অনুসন্ধানে স্থানান্তর করুন,নতুন কাছাকাছি অনুসন্ধানে স্থানান্তর করুন
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
ইউরোপিয়ান ইকোনমিক এরিয়া (EEA) ডেভেলপার এই পৃষ্ঠাটি Place
ক্লাস (নতুন) এবং PlacesService
(লেগেসি) এ ব্যবহৃত কাছাকাছি অনুসন্ধানের মধ্যে পার্থক্য ব্যাখ্যা করে এবং তুলনা করার জন্য কিছু কোড স্নিপেট প্রদান করে।
- Legacy
PlacesService
একটি nearbySearch()
পদ্ধতি রয়েছে, যা আপনাকে কীওয়ার্ড বা টাইপ দ্বারা একটি নির্দিষ্ট এলাকার মধ্যে স্থানগুলি অনুসন্ধান করতে দেয়৷ -
Place
ক্লাসে একটি searchNearby()
পদ্ধতি রয়েছে যা আপনাকে স্থানের ধরন অনুসারে একটি নির্দিষ্ট এলাকার মধ্যে স্থানগুলি অনুসন্ধান করতে দেয়, বৃহত্তর নমনীয়তার জন্য স্থানের ডেটা ক্ষেত্র এবং স্থানের প্রকারগুলির একটি বর্ধিত নির্বাচন ব্যবহার করে।
নিচের সারণীতে Place
শ্রেণী এবং PlacesService
মধ্যে কাছাকাছি অনুসন্ধান পদ্ধতির কিছু প্রধান পার্থক্য তালিকাভুক্ত করা হয়েছে:
কোড তুলনা
স্থান পরিষেবা এবং স্থান শ্রেণীর মধ্যে পার্থক্য চিত্রিত করতে এই বিভাগটি কাছাকাছি অনুসন্ধান পদ্ধতির কোড তুলনা করে। কোড স্নিপেট একটি পাঠ্য-ভিত্তিক অনুসন্ধান অনুরোধ করতে প্রতিটি সংশ্লিষ্ট API-এ প্রয়োজনীয় কোড দেখায়।
কাছাকাছি অনুসন্ধান (উত্তরাধিকার)
লিগ্যাসি কাছাকাছি অনুসন্ধান আপনাকে কীওয়ার্ড বা টাইপ দ্বারা একটি নির্দিষ্ট এলাকার মধ্যে স্থানগুলি অনুসন্ধান করতে দেয়৷ স্থান ডেটা ক্ষেত্রগুলি ব্যবহার করে অনুসন্ধানগুলিকে সীমাবদ্ধ করার কোনও উপায় নেই, যাতে প্রতিটি অনুরোধের সাথে সমস্ত উপলব্ধ ক্ষেত্র ফেরত দেওয়া হয়। নিম্নলিখিত স্নিপেটটি অস্ট্রেলিয়ার সিডনিতে রেস্তোরাঁ সম্পর্কে তথ্য ফেরত দিতে nearbySearch()
কল করা দেখায়। অনুরোধটি সিঙ্ক্রোনাস, একটি কলব্যাক ব্যবহার করে এবং PlacesServiceStatus
এ একটি প্রয়োজনীয় শর্তসাপেক্ষ চেক অন্তর্ভুক্ত করে।
let map;
let service;
function initMap() {
const sydney = new google.maps.LatLng(-33.867, 151.195);
map = new google.maps.Map(document.getElementById("map"), {
center: sydney,
zoom: 15,
});
const request = {
location: sydney,
radius: '500',
type: ['restaurant']
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
// Helper function to create markers.
function createMarker(place) {
if (!place.geometry || !place.geometry.location) return;
const marker = new google.maps.Marker({
map,
position: place.geometry.location,
title: place.name,
});
}
আরও জানুন
কাছাকাছি অনুসন্ধান (নতুন)
কাছাকাছি অনুসন্ধানের নতুন সংস্করণটি তার পূর্বসূরির উপর নিম্নলিখিত উপায়ে উন্নতি করে:
- কোন স্থানের ডেটা ক্ষেত্রগুলি ফেরত দিতে হবে তা নির্দিষ্ট করার ক্ষমতা।
- প্রতিশ্রুতির ব্যবহার যা অ্যাসিঙ্ক্রোনাস অপারেশন সক্ষম করে।
-
PlacesService
এর স্থিতি পরীক্ষা করার দরকার নেই; পরিবর্তে স্ট্যান্ডার্ড ত্রুটি হ্যান্ডলিং ব্যবহার করা যেতে পারে।
নিম্নলিখিত কোড স্নিপেট একটি ফাংশন দেখায় যা রেস্টুরেন্টের জন্য কাছাকাছি অনুসন্ধানের অনুরোধ করে। এই উদাহরণে rankPreference
অপশন ব্যবহার করে সার্চের ফলাফলকে জনপ্রিয়তার ভিত্তিতে র্যাঙ্ক করা দেখানো হয়েছে (পূর্ববর্তী সংস্করণে rankBy
বিকল্প ব্যবহার করে র্যাঙ্কিং নির্দিষ্ট করা হয়েছে)। যেহেতু searchNearby()
পদ্ধতিটি await
অপারেটর ব্যবহার করে এটি শুধুমাত্র একটি async
ফাংশনের মধ্যে ব্যবহার করা যেতে পারে।
async function nearbySearch() {
// Restrict within the map viewport.
let center = new google.maps.LatLng(52.369358, 4.889258);
const request = {
// Required parameters.
fields: ["displayName", "location", "businessStatus"],
locationRestriction: {
center: center,
radius: 500,
},
// Optional parameters.
includedPrimaryTypes: ["restaurant"],
maxResultCount: 5,
rankPreference: google.maps.places.SearchNearbyRankPreference.POPULARITY,
language: "en-US",
region: "us",
};
const { places } = await google.maps.places.Place.searchNearby(request);
if (places.length) {
console.log(places);
// Create a new bounds, which will be extended with each result.
const bounds = new google.maps.LatLngBounds();
// Loop through and get all the results.
places.forEach((place) => {
const markerView = new google.maps.marker.AdvancedMarkerElement({
map,
position: place.location,
title: place.displayName,
});
bounds.extend(place.location);
console.log(place);
});
map.fitBounds(bounds);
} else {
console.log("No results");
}
}
আরও জানুন
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-09-04 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-09-04 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Migrate to the new Nearby Search\n\n\u003cbr /\u003e\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\nThis page explains the differences between nearby search as used in the\n[`Place`](/maps/documentation/javascript/reference/place) class (new) and the\n[`PlacesService`](/maps/documentation/javascript/reference/places-service)\n(legacy), and provides some code snippets for comparison.\n\n- The legacy `PlacesService` has a `nearbySearch()` method, which lets you search for places within a specified area by keyword or type.\n- The `Place` class has a `searchNearby()` method which lets you search for places within a specified area by place type, utilizing an expanded selection of place data fields and place types for greater flexibility.\n\nThe following table lists some of the main differences in nearby search methods\nbetween the `Place` class and `PlacesService`:\n\n| [`PlacesService`](/maps/documentation/javascript/reference/places-service) (Legacy) | [`Place`](/maps/documentation/javascript/reference/place) (New) |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [`nearbySearch()`](/maps/documentation/javascript/reference/places-service#PlacesService.nearbySearch) | [`searchNearby()`](/maps/documentation/javascript/reference/place#Place.searchNearby) |\n| [`PlaceSearchRequest`](/maps/documentation/javascript/reference/places-service#PlaceSearchRequest) | [`SearchNearbyRequest`](/maps/documentation/javascript/reference/place#SearchNearbyRequest) |\n| Requires the use of a callback to handle the results object and `google.maps.places.PlacesServiceStatus` response. | Uses Promises, and works asynchronously. |\n| Requires a `PlacesServiceStatus` check. | No required status check, can use standard error handling. [Learn more](/maps/documentation/javascript/reference/errors). |\n| Supports only location bias. | Supports location bias and location restriction. |\n| Returns all available data fields (a [subset of the supported fields](/maps/documentation/places/web-service/place-data-fields#places-api-fields-support)); cannot be constrained to specific fields. | Returns only the requested [place data fields](/maps/documentation/javascript/place-class-data-fields); the `Place` class offers an expanded and regularly updated selection of fields. |\n| Limited to a fixed set of [place types](/maps/documentation/javascript/supported_types). | Access an expanded and regularly updated selection of [place types](/maps/documentation/javascript/place-types). |\n| Supported text-based search with the [keyword](/maps/documentation/javascript/reference/places-service#PlaceSearchRequest.keyword). | Text-based search is not supported, use [Text Search (New)](/maps/documentation/javascript/places-migration-search#place-class-new) instead. |\n\nCode comparison\n---------------\n\nThis section compares code for nearby search methods to illustrate the\ndifferences between the Places Service and the\nPlace class. The code snippets show the code\nrequired on each respective API to make a text-based search request.\n\n### Nearby Search (Legacy)\n\nThe legacy Nearby Search lets you search for places within a specified area by\nkeyword or type. There is no way to constrain searches by using place data\nfields, so that all of the available fields are returned with each request.\nThe following snippet shows calling `nearbySearch()` to return information about\nrestaurants in Sydney, Australia. The request is synchronous, uses a callback,\nand includes a required conditional check on `PlacesServiceStatus`. \n\n let map;\n let service;\n\n function initMap() {\n const sydney = new google.maps.LatLng(-33.867, 151.195);\n\n map = new google.maps.Map(document.getElementById(\"map\"), {\n center: sydney,\n zoom: 15,\n });\n\n const request = {\n location: sydney,\n radius: '500',\n type: ['restaurant']\n };\n\n service = new google.maps.places.PlacesService(map);\n service.nearbySearch(request, callback);\n }\n\n function callback(results, status) {\n if (status == google.maps.places.PlacesServiceStatus.OK) {\n for (var i = 0; i \u003c results.length; i++) {\n createMarker(results[i]);\n }\n }\n }\n\n // Helper function to create markers.\n function createMarker(place) {\n if (!place.geometry || !place.geometry.location) return;\n\n const marker = new google.maps.Marker({\n map,\n position: place.geometry.location,\n title: place.name,\n });\n }\n\n#### Learn more\n\n- [See the documentation for legacy Nearby Search](/maps/documentation/javascript/places#place_search_requests)\n- [See the `searchNearby()` reference](/maps/documentation/javascript/reference/places-service#PlacesService.nearbySearch)\n\n### Nearby Search (New)\n\nThe new version of Nearby Search improves upon its predecessor in the following\nways:\n\n- The ability to specify which place data fields to return.\n- The use of Promises which enables asynchronous operation.\n- No need to check for the status of `PlacesService`; standard error handling can be used instead.\n\nThe following code snippet shows a function which makes a Nearby Search request\nfor restaurants. This example shows using the `rankPreference` option to rank\nsearch results by popularity (in the previous version ranking is specified\nusing the `rankBy` option). Because the `searchNearby()` method uses the `await`\noperator it can only be used inside an `async` function. \n\n async function nearbySearch() {\n // Restrict within the map viewport.\n let center = new google.maps.LatLng(52.369358, 4.889258);\n const request = {\n // Required parameters.\n fields: [\"displayName\", \"location\", \"businessStatus\"],\n locationRestriction: {\n center: center,\n radius: 500,\n },\n // Optional parameters.\n includedPrimaryTypes: [\"restaurant\"],\n maxResultCount: 5,\n rankPreference: google.maps.places.SearchNearbyRankPreference.POPULARITY,\n language: \"en-US\",\n region: \"us\",\n };\n\n const { places } = await google.maps.places.Place.searchNearby(request);\n\n if (places.length) {\n console.log(places);\n\n // Create a new bounds, which will be extended with each result.\n const bounds = new google.maps.LatLngBounds();\n\n // Loop through and get all the results.\n places.forEach((place) =\u003e {\n const markerView = new google.maps.marker.AdvancedMarkerElement({\n map,\n position: place.location,\n title: place.displayName,\n });\n\n bounds.extend(place.location);\n console.log(place);\n });\n map.fitBounds(bounds);\n } else {\n console.log(\"No results\");\n }\n }\n\n#### Learn more\n\n- [See the complete example code](/maps/documentation/javascript/examples/place-nearby-search)\n- [See the documentation for Nearby Search (New)](/maps/documentation/javascript/nearby-search)\n- [See the `searchNearby()` reference](/maps/documentation/javascript/reference/place#Place.searchNearby)"]]