谷歌地图自动完成:仅输出没有国家和城市的地址 [英] Google maps Autocomplete: output only address without country and city

查看:112
本文介绍了谷歌地图自动完成:仅输出没有国家和城市的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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

From the docs:

the (cities) type collection instructs the Place service to return results that match either locality or administrative_area3.

var input = document.getElementById('searchTextField');
var options = {
  bounds: defaultBounds,
  types: ['(cities)']
};

autocomplete = new google.maps.places.Autocomplete(input, options);

这篇关于谷歌地图自动完成:仅输出没有国家和城市的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆