Google Autocomplete Language

I have the following situation. On the website, users submit the location of the apartments based on Google Autocomplete. They select a city from the list of Google offers, and I take this city and country (via api) and save them in the database.

Other users can search listings in this city using the Google AutoFill form as well. The problem occurs when users use different languages.

For ex-user 1 is located in the USA. When he submits his listing, I get google country "usa".

When user 2 (who lives in the Netherlands) using Google Autocomplete, I get the country "Verenigde Staten" (USA in duch). But the search algorithm will not function, since the presented list is saved as "united states" and not "Verenigde Staten".

Is there a way to show a list of sentences in the user's language, but get the results in English (so that I can save and search using only English). Maybe translate the results?

I know that I can “block” the list of sentences in English, but I would like to use this as a final measure.

This is my code.

input = (document.getElementById('property_city_front')); defaultBounds = new google.maps.LatLngBounds( new google.maps.LatLng(-90, -180), new google.maps.LatLng(90, 180) ); options = { bounds: defaultBounds, types: ['(cities)'], }; componentForm = { establishment: 'long_name', street_number: 'short_name', route: 'long_name', locality: 'long_name', administrative_area_level_1: 'long_name', administrative_area_level_2: 'long_name', country: 'long_name', postal_code: 'short_name', postal_code_prefix: 'short_name', neighborhood: 'long_name', }; if (document.getElementById('property_city_front')) { autocomplete = new google.maps.places.Autocomplete(input, options); google.maps.event.addListener(autocomplete, 'place_changed', function () { place = autocomplete.getPlace(); fillInAddress(place); }); } 

Following the suggestion, I return the place identifier (automatically completed in Dutch) and request PlacesService, but the results are still in Dutch, not English. Here is the code

  var request = { placeId: 'ChIJOwg_06VPwokRYv534QaPC8g', id: '7eae6a016a9c6f58e2044573fb8f14227b6e1f96', language:'en' }; map = new google.maps.Map(document.getElementById('searchmap'), { zoom: 15, scrollwheel: false }); service = new google.maps.places.PlacesService(map); service.getDetails(request, callback); function callback(place, status) { console.log(status); console.log (place); } 
+7
source share
1 answer

This question is most likely already answered here .

In short, the response contains an identifier that should be the same for both requests. You can use this identifier to determine the country that the user is looking for. According to the documentation:

id contains a unique stable identifier denoting this place. This identifier cannot be used to retrieve information about this place, but can be used to consolidate data about this place and to verify the identification of the place in different searches. Since identifiers can sometimes change, it is recommended that the stored identifier for a place be compared with the identifier returned later. Requests information for the same place and, if necessary, update.

You can request the Places API using the link. Link to another language. You can optionally add the received identifier.

+3
source

All Articles