【问题标题】:Bias results of place autocomplete for selected city所选城市的地点自动完成偏差结果
【发布时间】:2016-11-27 19:28:04
【问题描述】:

我有一个用于选择城市的下拉菜单和一个自动完成文本框。我只想要下拉列表中选定城市的位置。

function initAutocomplete() {
    autocomplete = new google.maps.places.Autocomplete(
            (document.getElementById('auto')),{
                bounds: new google.maps.Circle({
                    center: new google.maps.LatLng( 18.520430,73.856744 ),
                    radius: 500
                }).getBounds(),
                types: ['establishment']
            });

    autocomplete.addListener('place_changed', function(){});
}

我使用上面的代码进行地点自动完成,但我想动态地将经度和纬度传递给这个函数。我怎样才能做到这一点?请帮我。 我想要像 swiggy.com 这样的功能。

【问题讨论】:

    标签: javascript google-maps google-maps-api-3


    【解决方案1】:

    When new city is selected and you have new lat,lng of that city, use this piece of code to update the bound of autocomplete widget with new value of lat and lng:

    var bounds = new google.maps.LatLngBounds();
    var latLng = new google.maps.LatLng(lat, lng);
    bounds.extend(latLng);
    autocomplete.setBounds(bounds);
    

    【讨论】:

    • @ntahoang 这在概念上是如何工作的?我们只提供一个 2D 点。它只是获取最接近的东西?
    猜你喜欢
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 2018-03-24
    • 2011-05-15
    • 2017-11-29
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    相关资源
    最近更新 更多