【问题标题】:Bias location returns on Google Places API autocompleteGoogle Places API 自动完成功能返回偏向位置
【发布时间】:2013-08-24 06:30:42
【问题描述】:

我正在使用 Google Places API 来自动完成街道地址搜索。我想将结果偏向特定经度和纬度周围 50 英里的半径(这是一个固定位置,它不取决于用户)。目前,它会自动完成地址,但不会根据位置(除了在美国境内)来偏向它们。具体来说,我想在纬度:34.159947,经度:-118.257017 周围偏置 300 英里半径。

<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
        ...
<input id="address-search" type="text" value="" name="subject">


$(document).ready(function() {
    var input = document.getElementById('address-input');
    var options = {componentRestrictions: {country: 'us'} };               
    new google.maps.places.Autocomplete(input, options); 
    google.maps.event.addDomListener(window, 'load', initialize);
});

       

【问题讨论】:

    标签: javascript jquery google-places-api


    【解决方案1】:

    你不能给它一个半径,但你可以给它矩形边界

    var defaultBounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(-33.8902, 151.1759),
      new google.maps.LatLng(-33.8474, 151.2631)
    );
    
    var options = {bounds: defaultBounds };  
    

    Places Autocomplete documentation

    【讨论】:

    • 谢谢。顺便说一句,第 4 行有一个额外的括号
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    相关资源
    最近更新 更多