This guide highlights key differences between the legacy Places service and the new Place class. Upgrading to the Place class offers significant advantages, including improved performance and a new pricing model. To get the most out of Places and ensure your apps are up-to-date, familiarize yourself with the changes detailed in this guide.
Enable Places API
The Place class relies on the Places API service. To use the features of the new Place class, you must first enable Places API (New) in your Google Cloud project. For more information, see Get started.
General changes
The following table lists some of the main differences between PlacesService
and Place
:
PlacesService (Legacy) |
Place (New) |
---|---|
Methods require the use of a callback to handle the results object and
google.maps.places.PlacesServiceStatus response. |
Uses Promises, and works asynchronously. |
Methods require a PlacesServiceStatus check. |
No required status check, can use standard error handling. |
Place data fields are formatted using snake case. | Place data fields are formatted using camel case. |
Limited to a fixed set of place types and place data fields. | Provides an expanded selection of regularly updated place types and place data fields. |
API-specific changes
The Place class provides an API for using the Places library, and supports modern usage patterns such as Promises. The Place class exposes the same place data fields and place types as the legacy Places Service, and includes many new values for place data fields and place types.
This table shows how features of the Places service map to those of the Place class:
Load the Places library
How your app loads the Places library depends on which bootstrap loader is in
use. If your app uses dynamic library import,
you can load the needed libraries at runtime by using the await
operator to
call importLibrary()
, as shown here:
const { Place } = await google.maps.importLibrary("places");
If your app uses the direct script loading tag,
request the places
library in the loader script:
<script async
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async&libraries=places&callback=initMap">
</script>
Learn more about loading the Maps JavaScript API.
This section includes the following guides to help you migrate your apps to use the newest version of the Places API: