2012-06-04 123 views
1

我使用的是Google地方搜索,我希望海灣合作委員會國家(阿聯酋,沙特阿拉伯,阿曼,科威特&巴林)的「位置偏差」。谷歌地方搜索位置偏差

我想達到以下 https://developers.google.com/maps/documentation/places/autocomplete#location_biasing

我想提供一個文本框,谷歌搜索的地方,其中用戶只能看到來自這些國家的阿聯酋,沙特阿拉伯,阿曼,科威特&巴林的結果嗎?

感謝,


我可以「位置偏」關於使用「componentRestrictions」的說法一個國如在下面的代碼片段

var mapOptions = { 
      //bounds : defaultBounds, 
      center: new google.maps.LatLng(25.2644444, 55.31166669999993), 
      zoom: 13, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

     map = new google.maps.Map(document.getElementById('map_canvas'), 
      mapOptions); 

     var input = document.getElementById('searchTextField');   
     var InputOptions = { 
      types: ['(cities)'], 
      **componentRestrictions: { country: 'AE' } // I want multiple counteries here** 
     };     
     var autocomplete = new google.maps.places.Autocomplete(input, InputOptions); 

但我想多counteries位置自定義調整的是我在上面提到。

回答

1

你究竟想做什麼?

如果我找到你的想法,你只是想對這些國家之一進行地理編碼(阿聯酋,沙特阿拉伯,阿曼,科威特&巴林)?

function geocodeAddress() { 
    var address = "Oman"; 
    geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
     position: results[0].geometry.location // gives you the location 
     }); 
     } else { 
     alert("Error: " + status); 
     } 
    }); 
    } 
+0

我已經修改了問題的細節 – Tepu

+0

確定THX ...我會看看它 – libjup

+0

對不起...我還是不明白這一點:(做你想在下拉菜單中顯示阿聯酋,沙特阿拉伯,阿曼,科威特和巴林等國家的所有地名? – libjup

1

我認爲這是不可能的(目前)。將結果限制爲一個國家僅在幾個星期前被添加爲特徵。最好的選擇是限制如本例所示從Places Library website通過在地圖邊界的結果:

var defaultBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(-33.8902, 151.1759), 
    new google.maps.LatLng(-33.8474, 151.2631)); 

var input = document.getElementById('searchTextField'); 
var options = { 
    bounds: defaultBounds, 
    types: ['establishment'] 
}; 

autocomplete = new google.maps.places.Autocomplete(input, options); 

找到適合向你期望的區域範圍。