0

I have a problem about matching the cities with the addresses' city components. For example, I have a form which returns the city names with types parameter set to (regions) and one another form having the types parameter set as addresses.

Scenario, when I search this in the full address input:

14 rembrandplein

it gives me this components when I select the one in Amsterdam:

address_components: Array(8)
    0:
        long_name: "14"
        short_name: "14"
        types: ["street_number"]
    1:
        long_name: "Rembrandtplein"
        short_name: "Rembrandtplein"
        types: ["route"]
    2:
        long_name: "Amsterdam-Centrum"
        short_name: "Amsterdam-Centrum"
        types: (3) ["sublocality_level_1", "sublocality", "political"]
    3:
        long_name: "Amsterdam"
        short_name: "Amsterdam"
        types: (2) ["locality", "political"]
    4:
        long_name: "Amsterdam"
        short_name: "Amsterdam"
        types: (2) ["administrative_area_level_2", "political"]
    5:
        long_name: "Noord-Holland"
        short_name: "NH"
        types: (2) ["administrative_area_level_1", "political"]
    6:
        long_name: "Netherlands"
        short_name: "NL"
        types: (2) ["country", "political"]
    7:
        long_name: "1017 CV"
        short_name: "1017 CV"
        types: ["postal_code"]
length: 8

And I need to match the locality, administrative_area_level_1 and country parameters to the ones in the (regions) input. Which gives me this output for Amsterdam:

address_components: Array(4)
    0:
        long_name: "Amsterdam"
        short_name: "Amsterdam"
        types: (2) ["locality", "political"]
    1:
        long_name: "Government of Amsterdam"
        short_name: "Government of Amsterdam"
        types: (2) ["administrative_area_level_2", "political"]
    2:
        long_name: "North Holland"
        short_name: "NH"
        types: (2) ["administrative_area_level_1", "political"]
    3:
        long_name: "Netherlands"
        short_name: "NL"
        types: (2) ["country", "political"]

As you can see, the first one outputs Noord-Holland as administrative_area_level_1 component, and the second one gives North Holland.

I also tried setting the language parameter of the autocomplete initiator as en but still no luck.

The initiators:

Address input:

window["autocomplete_" + input.id] = new google.maps.places.Autocomplete( input, {
    types: ['address'],
    fields: ['address_components', 'types', 'formatted_address', 'place_id'],
    language: '<?php echo substr( get_locale ( ), 0, 2 );?>'
});

The city input:

var autocomplete = new google.maps.places.Autocomplete( input, {
    types: ['(regions)'],
    fields: ["address_components"],
    language: '<?php echo substr( get_locale ( ), 0, 2 );?>'
});

Thanks in advance.

Taha Paksu
  • 15,371
  • 2
  • 44
  • 78
  • `language` is not a valid option in https://developers.google.com/maps/documentation/javascript/reference/places-widget#AutocompleteOptions - try setting the language on the API script call. – MrUpsidown Aug 19 '19 at 09:56
  • Yes I've checked that, both is defined as `en_US`. Thanks for the heads up though. Changed the location of the definitions. But nothing changed. I'll try changing the "_" to "-" though. – Taha Paksu Aug 19 '19 at 10:48
  • Still the same with "-" instead "_". – Taha Paksu Aug 19 '19 at 10:50
  • `en_US`/`en-US` doesn't seem to be valid either... https://developers.google.com/maps/faq#languagesupport – MrUpsidown Aug 19 '19 at 10:54
  • I'll leave this because it has a similar question here. Voted to close my own question. – Taha Paksu Aug 19 '19 at 10:55

0 Answers0