最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Maps API - Migration of Autocomplete class to PlaceAutocompleteElement class - Stack Overflow

programmeradmin2浏览0评论

I got to know that Google is deprecating it's old places api and replacing with the new one's. In our application, we use Maps Javascript api with the library=places param, The following way: =${apiKey}&libraries=places. We are using Autocomplete class and a method in it getPlace() for our maps. But I have seen that the Autocomplete class is old and we have to migrate to new class PlaceAutocompleteElement -

Do we really need to make changes to the old Autocomplete class and replace it with a new PlaceAutocompleteElement class? Is the old one getting deprecated any soon in the near time?

autocomplete = new GoogleApi.maps.places.Autocomplete(
      document.getElementById('startIcon'),
      {
        componentRestrictions: { country: country },
      },
    );

I got to know that Google is deprecating it's old places api and replacing with the new one's. In our application, we use Maps Javascript api with the library=places param, The following way: https://maps.googleapis/maps/api/js?key=${apiKey}&libraries=places. We are using Autocomplete class and a method in it getPlace() for our maps. But I have seen that the Autocomplete class is old and we have to migrate to new class PlaceAutocompleteElement - https://developers.google/maps/documentation/javascript/places-migration-overview#api-specific_changes

Do we really need to make changes to the old Autocomplete class and replace it with a new PlaceAutocompleteElement class? Is the old one getting deprecated any soon in the near time?

autocomplete = new GoogleApi.maps.places.Autocomplete(
      document.getElementById('startIcon'),
      {
        componentRestrictions: { country: country },
      },
    );

We also use some of the fields which autocomplete.getPlace() method offers. Like formatted_address, address_components, geometry.location, name and others. Even these data fields are getting replaced. So, the question is the same. Should I truly make any changes to my code and follow new Places class when using places library?

Do I require a new API key if I want to do the above changes? Because https://developers.google/maps/documentation/javascript/place-get-started#get-an-api-key-and-enable-the-required-apis says the new api key is only for new Text search but we are not using it.

Share Improve this question edited Mar 3 at 18:30 Sam76 asked Mar 3 at 18:09 Sam76Sam76 112 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

I'm running into this issue with my WordPress plugin, and I'm already getting customers who can't get the AutoComplete feature to work. It's because any new Google API users can no longer use the legacy class google.maps.places.Autocomplete and can only use the new class. For existing customers, there is no problem. I really don't understand why they did this and didn't provide a fallback method because now I'm basically screwed and need to figure out how to do everything from scratch. My plugin uses this API extensively, and it's quite complicated to migrate to the new class.

Here are some key takeaways:

  • google.maps.places.Autocomplete still works for existing projects created before March 1, 2025.
  • New API keys or new projects created after March 1, 2025 cannot use the legacy class. Google recommends migrating to PlaceAutocompleteElement.
  • The legacy class will continue to get major bug fixes, but no feature updates.
  • Google promises at least 12 months notice before disabling it
    completely.

So if you are an existing user, just stick to the old class and you should be notified 12 months prior to full deprecation.

For new users, you must use the new class (and enable both legacy and new API for your project). Unfortunitely for me that means I have to get to work and make sure my software works with the new API otherwise any new Google API users won't be able to use the feature in my software...

More info about this can be read in the migration guide for google.maps.places.Autocomplete: https://developers.google/maps/documentation/javascript/places-migration-autocomplete

The google.maps.places.Autocomplete() class is part of the Places API (Legacy), which requires separate activation and has been deprecated since March 1, 2025. This will no longer work for the Places API (New), so in your case, you indeed need to update your code to replace it with the PlaceAutocompleteElement class. Additionally, the documentation states that the Places API (New) should also be enabled, as it is required not only for Text Search (New) but also for Place Autocomplete.

Note: Legacy services will no longer receive new feature updates nor will it receive any bug fixes, whether minor or major.

发布评论

评论列表(0)

  1. 暂无评论