0

我在将城市与地址的城市组成部分匹配时遇到问题。例如,我有一个表单,它返回参数设置为的城市名称,types(regions)另一个表单的types参数设置为addresses.

场景,当我在完整地址输入中搜索时:

14 伦勃朗广场

当我在阿姆斯特丹选择一个组件时,它给了我这个组件:

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

我需要将locality,administrative_area_level_1country参数与(regions)输入中的参数相匹配。这给了我这个输出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"]

如您所见,第一个输出Noord-Holland作为administrative_area_level_1组件,第二个输出North Holland

我还尝试将自动完成启动器的语言参数设置为en但仍然没有运气。

发起人:

地址输入:

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 );?>'
});

城市输入:

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

提前致谢。

4

0 回答 0