Reputation: 374
I am building a locality search functionality to show localities from a specific city. User will filter contents on a city page.
For this I am using Google Maps JavaScript API
This API has component restriction at Country level.
var options = {
types: ['(regions)'],
componentRestrictions: {country: 'in'}};
Now in this case, since I already know the city, I want to get the locality results for that particular city onyl.
Is there any filter for the same in this API>
Upvotes: 1
Views: 2186
Reputation: 32148
Currently there is no components filter for city in Places API.
You can see a feature request in the public issue tracker for this. Have a look at ticket 4433 and star it to add your vote.
As a workaround you can try to use city boundaries and strictBounds property of autocomplete:
https://developers.google.com/maps/documentation/javascript/reference#AutocompleteOptions
Upvotes: 1
Reputation: 374
Well I did managed to achieve it in the following way.
I filtered out the results which didn't contain the selected city
document.addEventListener("DOMNodeInserted", function() {
$('.pac-container div').each(function() {
if($(this).text().toLowerCase().search(cityName.toLowerCase()) == "-1") {
$(this).hide();
}
});
});
So out of the results for a country I filtered out those which didn't match the cityName
Upvotes: 0