Google map api autocomplete restricted/bias to street address in my town

后端 未结 4 1714
一生所求
一生所求 2021-01-05 23:18

I am trying to write a web application for my final year project at uni, and one of the first problems i need to tackle is getting an auto complete text box for local addres

4条回答
  •  再見小時候
    2021-01-06 00:05

    var input = document.getElementById('inputSearch');
    var cityBounds = new google.maps.LatLngBounds(
            new google.maps.LatLng(12.864162, 77.438610),
            new google.maps.LatLng(13.139807, 77.711895));
    var options = {
            bounds: cityBounds,
            strictBounds: true,
            componentRestrictions: {country: 'in'}
        };
    var inputBox = new google.maps.places.Autocomplete(input, options);
    google.maps.event.addListener(inputBox, 'place_changed', function() {
            var place = inputBox.getPlace();
            console.log(place.geometry.location.lat() +', '+ place.geometry.location.lng());
        });
    

    This works great for me!

提交回复
热议问题