javascript - Google Maps API: How to get street addresses only as results of Autocomplete - Stack Overflow

Given the bounds of a specific city in the form of a google.maps.LatLngBounds type variable, I want to

Given the bounds of a specific city in the form of a google.maps.LatLngBounds type variable, I want to get street addresses from that specific area as results of the autoplete feature.

I read that using bounds in Google Maps API gives only approximate results and that would work for me. Problem is: at the moment results are not even close to the specified area.

<input type="text" class="event_form_input" id="event_address" name="event_address" placeholder="Address" value="">
var address_input = document.getElementById('event_address');
var address_autoplete = new google.maps.places.Autoplete(address_input,{bounds: event_city_bounds, types: ['geocode']});

address_autoplete.addListener('place_changed', function(){               
                var event_address=address_autoplete.getPlace();
})

What I am getting are both city names and addresses with no restrictions at all. I already checked the variable event_city_bounds and it always contains the correct bounds of any city I previously select (from another input menu). Hope someone can help.

Given the bounds of a specific city in the form of a google.maps.LatLngBounds type variable, I want to get street addresses from that specific area as results of the autoplete feature.

I read that using bounds in Google Maps API gives only approximate results and that would work for me. Problem is: at the moment results are not even close to the specified area.

<input type="text" class="event_form_input" id="event_address" name="event_address" placeholder="Address" value="">
var address_input = document.getElementById('event_address');
var address_autoplete = new google.maps.places.Autoplete(address_input,{bounds: event_city_bounds, types: ['geocode']});

address_autoplete.addListener('place_changed', function(){               
                var event_address=address_autoplete.getPlace();
})

What I am getting are both city names and addresses with no restrictions at all. I already checked the variable event_city_bounds and it always contains the correct bounds of any city I previously select (from another input menu). Hope someone can help.

Share Improve this question asked Oct 18, 2016 at 11:05 AndrewAndrew 46811 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Types supported in place autoplete requests:

address instructs the Place Autoplete service to return only geocoding results with a precise address. Generally, you use this request when you know the user will be looking for a fully specified address.

So you can try something like this

var address_autoplete = new google.maps.places.Autoplete(address_input,{bounds: event_city_bounds, types: ['address']});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745513441a4630875.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信