【发布时间】:2016-03-16 13:03:54
【问题描述】:
我有这个代码
var input, defaultBounds, autocomplete_normal;
input = (document.getElementById('search_location'));
defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-90, -180),
new google.maps.LatLng(90, 180)
);
var options = {
bounds: defaultBounds,
types: ['(cities)']
};
autocomplete_normal = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete_normal, 'place_changed', function () {
var place = autocomplete_normal.getPlace();
console.log(place);
});
当我搜索“葡萄牙科英布拉”时,Api 的地方会将“科英布拉”作为“地点”返回 - 应该如此。
但是,如果我将 types: ['(cities)'] 替换为 types: ['geocode'] ,则“Coimbra”将返回为“administrative_area_level_2”,并且没有其他关于位置的信息。
类型为 ['(cities)'] 的代码用于提交页面以获取城市。类型为 ['geocode'] 的代码用于搜索表单,在这种情况下不会返回正确的结果,因为“locality”变量为空。
我尝试将地理编码替换为“(区域)”,但结果相同。你能告诉我为什么会这样吗?为什么这只发生在某些地方?
【问题讨论】:
标签: google-maps google-maps-api-3 google-places-api