Stay organized with collections Save and categorize content based on your preferences.
The Places API can return detailed information about a specific place. This page explains the differences between place details as used in the Place
class (new) and PlacesService
(legacy), and provides some code snippets for comparison. The following table lists some of the main differences in the use of place details between the Place
class and PlacesService
:
This section compares two similar pieces of code 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 place details request, and then use the resulting place data to add a marker to the map.
Places Service (Legacy)The following condensed code snippet shows making a place details request using PlacesService
. The request uses a callback, and includes a required conditional check on PlacesServiceStatus
. The needed place data fields are specified in the request body.
function getPlaceDetails() {
// Instantiate the Places Service.
const service = new google.maps.places.PlacesService(map);
// Make a request using the Place ID.
const request = {
placeId: "ChIJN1t_tDeuEmsRUsoyG83frY4",
fields: ["name", "formatted_address", "place_id", "geometry"],
};
// Request place details.
service.getDetails(request, (place, status) => {
// Check whether PlacesServiceStatus is OK.
if (
status === google.maps.places.PlacesServiceStatus.OK &&
place &&
place.geometry &&
place.geometry.location
) {
// Log the result.
console.log(place.name);
console.log(place.formatted_address);
// Add a marker for the place.
const marker = new google.maps.Marker({
map,
position: place.geometry.location,
title: place.name,
});
}
});
}
Learn more
getDetails
referenceThe following condensed code snippet shows making a place details request using the Place
class. The request is asynchronous, and does not include a status check (standard error handling can be used). A place ID is used to create a new Place
instance, which is used to make the request (fetchFields()
). The needed place data fields are not passed until fetchFields()
is called, which lends greater flexibility. Because the fetchFields()
method uses the await operator it can only be used inside an async
function.
async function getPlaceDetails() {
// Use place ID to create a new Place instance.
const place = new google.maps.places.Place({
id: "ChIJN5Nz71W3j4ARhx5bwpTQEGg",
requestedLanguage: "en", // optional
});
// Call fetchFields, passing the needed data fields.
await place.fetchFields({
fields: ["displayName", "formattedAddress", "location"],
});
// Log the result.
console.log(place.displayName);
console.log(place.formattedAddress);
// Add an Advanced Marker.
const marker = new google.maps.marker.AdvancedMarkerElement({
map,
position: place.location,
title: place.displayName,
});
}
Learn more
Except 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-08-14 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-08-14 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