Cre*_*rem 7 jquery google-places-api
我有以下情况.在网站上,用户根据Google自动填充功能提交公寓位置.他们从谷歌建议列表中选择一个城市,然后我将这个城市和国家(通过api)保存到数据库中.
其他用户也可以使用Google自动填充表单在该城市中搜索列表.当用户使用不同的语言时,会出现此问题.
对于前用户1在美国.当他提交他的列表我从谷歌收到国家"美国".
当用户2(住在荷兰)使用谷歌自动填充搜索我收到国家"Verenigde Staten"(美国杜赫).但搜索算法将无法运行,因为提交的列表保存为"美国"而不是"Verenigde Staten".
有没有办法用用户语言显示建议列表但是用英语接收结果(所以我可以只用英语保存和搜索).也许翻译结果?
我知道我可以用英语"阻止"建议清单,但我想用这个作为最终措施.
这是我的代码
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);
});
}
Run Code Online (Sandbox Code Playgroud)
根据建议,我将检索地点ID(自动完成荷兰语)并查询PlacesService,但我得到的结果仍然是荷兰语而不是英语.这是代码
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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1523 次 |
| 最近记录: |