Google provides two ways to achieve this. If you are not comfortable, because in countries such as India, this does not work well, because there are no rectangular or structural borders in states and states.
1.LatLngBounds (LatLng southwest, LatLng northeast):. Here you can highlight latitude and longitude to form a rectangle.
2. Location (Lat, Lng) and Radius:. Here you can specify latitude and longitude to form a circle.
But the problem with these approaches does not give the expected results if you are from countries such as India, where states and states do not have structured forms (Rectangular), as in the USA.
If you are faced with the same problem as there is a hack. With jQuery / Jacascript, you can attach functions that will sequentially save the city name in text input, which is limited by the Places API Autocomplete object.
Here he is:
<script> $(document).ready(function(){ $("#locality").val(your-city-name) //your-city-name will have city name and some space to seperate it from actual user-input for example: "Bengaluru | " }); $("#locality").keydown(function(event) { //locality is text-input box whixh i supplied while creating Autocomplete object var localeKeyword = "your-city-name" var localeKeywordLen = localeKeyword.length; var keyword = $("#locality").val(); var keywordLen = keyword.length; if(keywordLen == localeKeywordLen) { var e = event || window.event; var key = e.keyCode || e.which; if(key == Number(46) || key == Number(8) || key == Number(37)){ e.preventDefault(); }//Here I am restricting user to delete city name (Restricting use of delete/backspace/left arrow) if length == city-name provided if(keyword != localeKeyword) { $("#locality").val(localeKeyword); }//If input-text does not contain city-name put it there } if(!(keyword.includes(localeKeyword))) { $("#locality").val(localeKeyword); }//If keyworf not includes city name put it there }); </script>
(Image :) Before this hack

(Image :) After this hack

Ravi upadhyay
source share