How to restrict google places to specific city

后端 未结 3 1571
时光说笑
时光说笑 2020-12-10 16:37

I am currently able to restrict places to only one country, but I also want to restrict on a specific city also. Any ideas how to achieve that? This is my current code:

3条回答
  •  臣服心动
    2020-12-10 16:47

    Places Autocomplete currently allows you to use componentRestrictions to filter by country. What I would do in your situation is to use the options argument to filter by the bounds that define the city in question:

    var cityBounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(25.341233, 68.289986),
      new google.maps.LatLng(25.450715, 68.428345));
    
    var options = {
      bounds: cityBounds,
      types: ['geocode'],
      componentRestrictions: {country: 'est'}
    };
    

提交回复
热议问题