如何将谷歌自动完成表单的语言设置为英语
How to set the language of google autocomplete form to English?
我正在遵循这个谷歌的例子,这个地方自动完成地址表单。
问题是,如果我插入"罗马,意大利",表格将返回城市"罗马"和国家"意大利"(语言为意大利语)。我不想要意大利名字,我想要英文名字。在同一示例中,如果我插入"罗马,意大利"或"罗马,意大利",我希望表单返回城市"罗马"和国家/地区"意大利"。
我应该怎么做才能将表格的语言设置为英语?
这里是javascript部分:
var placeSearch, autocomplete;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
function initAutocomplete() {
// Create the autocomplete object, restricting the search to geographical
// location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
{types: ['geocode']});
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}
// Get each component of the address from the place details
// and fill the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}
// Bias the autocomplete object to the user's geographical location,
// as supplied by the browser's 'navigator.geolocation' object.
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
这里是带有密钥的 api:
<script src="https://maps.googleapis.com/maps/api/js?key=[API key]&libraries=places&callback=initAutocomplete" async defer></script>
提前致谢
您可以通过向
脚本标记添加&language=[language here]
来更改语言。对于英语,这将是:&language=en
举个例子:
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&language=en"
type="text/javascript">
</script>
这里对此进行了描述,这里有一个工作示例。
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 如何使用WCF服务和javascript表单post上传.doc文件
- Javascript生成的表单未提交
- 如何使用javascript或html下载PDF格式的填写表单
- HTML表单提交时未执行外部函数
- 如何将输入(type=text)从html表单传递到javascript函数
- 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码
- Ajax发布表单序列化,发布引号'
- 多级HTML表单
- 后焦点更改为IE 11中的地址栏,而不是转移到表单中的下一个控件
- 在验证和发送邮件后更改联系人表单的 html
- jQuery表单添加不适用于下拉列表
- Rails/JSON:如何将JSON用于jquery UI自动完成表单
- 如何从 django 模板语言获取表单数据
- 不是语言切换专家点击智能表单需要提示
- 如何处理多种语言的表单验证(特殊字符):AngularJS
- 如何将谷歌自动完成表单的语言设置为英语
- 如何根据浏览器语言的变化翻译“浏览”或“选择文件”的表单输入类型=文件
- 如何在rails表单中填写数据时在英语和其他语言之间切换
- 更改表单的语言