2016-11-28 1 views
0

내 요구 사항은 Bangalore에있는 장소에 대해서만 Google 지역 정보 자동 완성 제안을 얻는 것이지만 방갈로르 이외의 다른 장소를 검색하면 원하지 않는 제안을 받게됩니다. 내 질문에 관련된 많은 stackoverflow 링크를 발견했지만 그들 중 누구도 내 문제를 해결하고 있습니다.Google지도 자동 완성을 특정 도시로 제한하려면 어떻게해야합니까?

특정 도시의 제안을 얻을 수 있습니까?

내가 아래에있는 내 코드를 공유하고

: -

var input = (document.getElementById('address')); 
      var s_w = new google.maps.LatLng(12.97232, 77.59480); //southwest 
      var n_e = new google.maps.LatLng(12.89201, 77.58905); //northeast 
      var b_bounds = new google.maps.LatLngBounds(s_w, n_e); //bangalorebounds 

var options = { 
      bounds:b_bounds, 
      componentRestrictions: {country: "in"} 
      }; 
var autocomplete = new google.maps.places.Autocomplete(input, options); 

autocomplete.bindTo('bounds', map); 

autocomplete.addListener('place_changed', function() { 

    //rest_of_the_code 

}); 

누군가가 도와주세요!

답변

1

난 당신이 시도 할 수 있다고 생각 :

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'} 
}; 

는 국가 코드 LatLng 당신의 가치와 가치와 country를 교체합니다.

+0

다른 도시의 제안도 제공합니다. – sajalsuraj

+0

https://developers.google.com/maps/documentation/javascript/reference#AutocompletionRequest에 따르면 '경계'및 '구성 요소 제한'을 사용할 수 있습니다. 또 다른 대안은 '위치'를 사용하는 것입니다. 제안은 API에서 사용하는 위치를 기반으로합니다. –

+0

ok 대체 위치로 시도합니다. – sajalsuraj

1

경계를 사용하여 결과를 바이어스 할 수 있지만 현재 자동 완성 된 장소에는 도시별로 엄격한 필터가 없습니다.

당신은 공공 이슈 트래커에 더 엄격한 필터를 추가하는 기능 요청을 찾을 수 있습니다

https://code.google.com/p/gmaps-api-issues/issues/detail?id=4433

관심을 표현하고 구글에서 업데이트를받을 수있는이 기능 요청을 스타하십시오.

+0

고마워요. 시도 할 것입니다 .. – sajalsuraj

3

이렇게 해보십시오.

var bangaloreBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(12.864162, 77.438610), 
    new google.maps.LatLng(13.139807, 77.711895)); 

var autocomplete = new google.maps.places.Autocomplete(this, { 
    bounds: bangaloreBounds, 
    strictBounds: true, 
}); 

autocomplete.addListener('place_changed', function() { 

}); 

참고 : URL이 있어야한다 : https://maps.googleapis.com/maps/api/js?libraries=places&key=YOUR_API_KEY

strictBounds option가 (2017 년 1 월) 실험 버전 현재지도 자바 스크립트 API의 버전 3.27에서 추가되었다.

관련 문제