Google Maps API v3:Radius参数似乎不会限制自动填充结果

时间:2013-05-01 19:55:20

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

我正在尝试通过componentRestrictions和半径radius设置国家/地区,将自动填充结果限制为某个城市,如下所述: https://developers.google.com/maps/documentation/javascript/places

国家限制可行,不幸的是半径(在这种情况下应限制在500米范围内的地址)!你能救我吗?

<script src="https://maps.googleapis.com/maps/api/js?&amp;sensor=false&amp;region=it&libraries=places"></script>

    <script>
    var directionsDisplay;
    var directionsService = new google.maps.DirectionsService();
    var map;

    function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var myLatlng = new google.maps.LatLng(41.88994,12.51383);

    var mapOptions = {
        zoom:16,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: myLatlng,
        styles: [
            {
                featureType: "poi.business",
                elementType: "labels",
                stylers: [
                        { visibility: "off" }
                ]
            }
        ]
      }

    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById('directions-panel'));


    var input = document.getElementById('start');
var options = {
  types: ['geocode'],
  componentRestrictions: {country: 'it'},
radius: '500',
};
    var autocomplete = new google.maps.places.Autocomplete(input, options);

    autocomplete.bindTo('bounds', map);


    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'My Marker'
    });





    }



    function calcRoute() {
        var start = document.getElementById('start').value;
        if (start.indexOf("Roma") === -1) {
            start += ", Roma";
        }
          var end = "Via Tiburtina 500, Roma";
          var request = {
            origin:start,
            destination:end,
            travelMode: google.maps.DirectionsTravelMode.TRANSIT
          };
        directionsService.route(request, function(response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
          }
        });
    }

    google.maps.event.addDomListener(window, 'load', initialize);
    </script>

    <form onsubmit="calcRoute(); return false">
        <input type="text" id="start" name="start" placeholder="Indirizzo di partenza" style="margin-left:5px;width:200px">
        <input type="submit" value="Vai">
    </form>


        <div id="map-canvas" style="width: 927px; margin-top:5px;margin-left:5px; height: 300px; position: relative;"></div>
        <div id="directions-panel"></div>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

地方没有radius - 选项。自动填充,只有bounds-option来限制区域