最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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']});
发布评论

评论列表(0)

  1. 暂无评论