Stay organized with collections Save and categorize content based on your preferences.
This page explains the differences between text-based place search features in the Place
class (new) and the PlacesService
(legacy), and provides some code snippets for comparison.
The legacy PlacesService
has the following text-based search methods:
findPlaceFromQuery()
method which takes a text query and returns a single place result, and supports the use of place data fields.findPlaceFromPhoneNumber()
method which lets you search for a place using a phone number, and supports the use of place data fields.textSearch()
method which takes a text query and returns a list of place results. textSearch()
is older, and does not support the use of place data fields.The new Place
class offers the Place.searchByText()
method, which lets you search for places using either a text query or phone number, and lets you customize your searches using an expanded selection of regularly updated place data fields and place types.
The following table lists some of the main differences in place search methods between the Place
class and PlacesService
:
This section compares code for text search methods to illustrate the differences between the Places Service and the Place class. The code snippets show the code required on each respective API to make a text-based search request.
Places Service (Legacy)The following code snippet shows using the findPlaceFromQuery()
method to search for a place. The request is synchronous, and includes a conditional check on PlacesServiceStatus
. The needed place data fields are specified in the request body, which is defined prior to making the actual request.
function findPlaces() {
const request = {
query: "Museum of Contemporary Art Australia",
fields: ["name", "geometry"],
};
// Create an instance of PlacesService.
service = new google.maps.places.PlacesService(map);
// Make a findPlaceFromQuery request.
service.findPlaceFromQuery(request, (results, status) => {
let place = results[0];
if (status === google.maps.places.PlacesServiceStatus.OK && results) {
if (!place.geometry || !place.geometry.location) return;
const marker = new google.maps.Marker({
map,
position: place.geometry.location,
});
map.setCenter(place.geometry.location);
}
});
}
Learn more
Text Search (New)
The following code snippet shows using the searchByText()
method to search for places. The request is asynchronous, and does not require a status check (standard error handling can be used). In this example, the request includes a maxResultCount
of 8 (value must be between 1 and 20). This function loops through the results and adds a marker for each one, adjusting the map bounds based on the position of the markers. Because the searchByText()
method uses the await
operator it can only be used inside an async
function.
async function findPlaces() {
// Define a request.
// The `fields` property is required; all others are optional.
const request = {
fields: ["displayName", "location", "businessStatus"],
textQuery: "Tacos in Mountain View",
includedType: "restaurant",
locationBias: { lat: 37.4161493, lng: -122.0812166 },
isOpenNow: true,
language: "en-US",
maxResultCount: 8,
minRating: 3.2,
region: "us",
useStrictTypeFiltering: false,
};
// Call searchByText passing the request.
const { places } = await google.maps.places.Place.searchByText(request);
// Add a marker for each result.
if (places.length) {
const bounds = new google.maps.LatLngBounds();
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");
}
}
The searchByText()
method supports many more request options compared to the previous version, including:
includedType
which lets you constrain searches to a specific place type.isOpenNow
which lets you restrict searches to only return places that are open.minRating
which lets you filter out results below the specified limit (for example, only return places with three stars or more).locationRestriction
which omits results outside of the specified location (locationBias
is also supported).searchByText()
referenceExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-11 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-11 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4