谷歌地图自动完成:仅输出没有国家和城市的地址 [英] Google maps Autocomplete: output only address without country and city
问题描述
我使用 Places库自动完成地址输入。搜索仅限于一个城市,我得到这样的输出:
Rossiya,Moskva,Leninskiy prospekt 28
如何隐藏Rossiya,Moskva? ...
我的查询:
function(){
//搜索边界
var p1 = new google.maps.LatLng(54.686534,35.463867);
var p2 = new google.maps.LatLng(56.926993,39.506836);
self.options = {
界限:新的google.maps.LatLngBounds(p1,p2),
componentRestrictions:{country:'ru'},
};
var elements = document.querySelectorAll('。address');
for(var i = 0; i< elements.length; i ++){
var autocomplete = new google.maps.places.Autocomplete(elements [i],
self.options);
strong>
你不能。我反其道而行,你只是在寻找一个城市。没有办法只从地址组件中打印出街道名称(我假设这是一个街道名称)。 a href =https://developers.google.com/maps/documentation/javascript/places#adding_autocomplete =nofollow>来自文档:
(城市)类型集合指示Place服务返回匹配
locality
或administrative_area3
。
var input = document.getElementById('searchTextField');
var options = {
界限:defaultBounds,
类型:['(cities)']
};
autocomplete = new google.maps.places.Autocomplete(input,options);
I use Places library to autocomplete address input. Search is limited to only one city, and I get output like this:
"Rossiya, Moskva, Leninskiy prospekt 28"
How to hide "Rossiya, Moskva"? ...
My query:
function() {
// Search bounds
var p1 = new google.maps.LatLng(54.686534, 35.463867);
var p2 = new google.maps.LatLng(56.926993, 39.506836);
self.options = {
bounds : new google.maps.LatLngBounds(p1, p2),
componentRestrictions: {country: 'ru'},
};
var elements = document.querySelectorAll('.address');
for ( var i = 0; i < elements.length; i++) {
var autocomplete = new google.maps.places.Autocomplete(elements[i],
self.options);
}
EDIT
You can't. I had it the other way around, that you were just looking for a city. There is no way to only print out the street name (I'm assuming that's a street name) from the address component.
OPPOSITE OF WHAT WAS ASKED
the (cities) type collection instructs the Place service to return results that match either
locality
oradministrative_area3
.
var input = document.getElementById('searchTextField');
var options = {
bounds: defaultBounds,
types: ['(cities)']
};
autocomplete = new google.maps.places.Autocomplete(input, options);
这篇关于谷歌地图自动完成:仅输出没有国家和城市的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!