Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port this over to Places API (New)? #841

Open
BenJackGill opened this issue Apr 4, 2024 · 7 comments
Open

Port this over to Places API (New)? #841

BenJackGill opened this issue Apr 4, 2024 · 7 comments
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@BenJackGill
Copy link

BenJackGill commented Apr 4, 2024

Is your feature request related to a problem? Please describe.
I am looking for a npm package to use with Places API (New) (places.googleapis.com) as opposed to the original Places API (places-backend.googleapis.com) which this package currently uses. I was hoping this one could be ported/copied/modified to work with the Places API (New).

Describe the solution you'd like
New npm package for Places API (New) (places.googleapis.com) to be used on client browsers. Or change this one so it supports the new API.

Describe alternatives you've considered
This package, but it does not work with the new API.

Additional context
None

@BenJackGill BenJackGill added triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Apr 4, 2024
@wangela
Copy link
Member

wangela commented Apr 4, 2024

If you would like to upvote the priority of this issue, please comment below or react on the original post above with 👍 so we can see what is popular when we triage.

@BenJackGill Thank you for opening this issue. 🙏
Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

@usefulthink
Copy link
Contributor

@BenJackGill this package doesn't really interact with the Places API at all, it only loads the Google Maps JavaScript API in the browser. I don't think there is a way to choose the version of the places library that is used by the Maps API (i.e., when loading it via google.maps.importLibrary('places')).

@usefulthink usefulthink removed the triage me I really want to be triaged. label Apr 4, 2024
@BenJackGill
Copy link
Author

BenJackGill commented Apr 4, 2024

I think it does interact with the Places API when it loads the libraries.

I am using this package for Places autocomplete, and I restrict my API credentials to only the APIs that need access (principle of least privilege).

In doing so, for this package to work it requires access to both the Maps JavaScript API (maps-backend.googleapis.com) and Places API (places-backend.googleapis.com). Without access to the Places API it throws an error saying This API key is not authorized to use this service or API. Places API error: ApiTargetBlockedMapError which suggest thats this package is using the Places API somewhere.

Here is my code that uses @googlemaps/js-api-loader to load the Places library:

import { Loader } from "@googlemaps/js-api-loader";

  const loader = new Loader({
    apiKey: process.env.GCP_PLACES_API_KEY || "",
    version: "weekly",
    libraries: ["places"], // <--- Maybe this is where it uses Places API?
  });
  await loader.load();
  autocompleteService = new google.maps.places.AutocompleteService();
  sessionToken.value = new google.maps.places.AutocompleteSessionToken();

// More stuff here for autocomplete predictions

I tried migrating from the old Places API to the new one by changing the API credential restriction from places-backend.googleapis.com to places.googleapis.com and it started throwing the same error of This API key is not authorized to use this service or API. Places API error: ApiTargetBlockedMapError which suggests that the package only works with original places-backend.googleapis.com and not the new places.googleapis.com version.

So my feature request was hoping to either get the new places.googleapis.com version working here or maybe a standalone package if that is a better direction.

Maybe I am asking this in the wrong place?

@usefulthink
Copy link
Contributor

Ah, I see. Indeed, the 'places' library dependency of the maps API is still mostly using the older version of the places API. As far as I know, only the new Place class and other new parts of the places library are using the newer version of the API.

I think these new classes are meant to supercede and eventually replace the PlacesService and related classes, but I tend to believe the two versions are going to coexist for quite a while.

@wangela
Copy link
Member

wangela commented Apr 30, 2024

@BenJackGill Indeed, the line libraries: ["places]" loads the Places library which provides access to both the old and the new Places APIs.

See the Get Started with Place class page to make sure you've enabled the Places API (New) on the project associated with your API key and you've added the new API to your list of restrictions applied to that key.

If you're looking for the new Place Autocomplete you can use the widget provided as an HTML element here: https://developers.google.com/maps/documentation/javascript/place-autocomplete-new

@tiefenb
Copy link

tiefenb commented May 15, 2024

We use also the Places API for autocomplete with this library. We got contacted by Google who asked if we could move to the new Places API (new). Now we are waiting of the support by this library.

@usefulthink
Copy link
Contributor

If you want to move to Places API (new), you can just start by using the new Place class as mentioned by @wangela above.
Nothing in way you're loading the Maps API needs to be changed for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants