2013-10-18 57 views
1

我從Google的地理編碼器API開始,我只想返回street_address的location_type。Geocoder API僅返回街道地址

唯一的問題,我不知道誰來具體要求。這裏是我的代碼現在:

var geocoder = new google.maps.Geocoder(); 
geocoder.geocode({'latLng':myLatLng}, function(results, status){ 
    if(status == google.maps.GeocoderStatus.OK){ 
     if(results.length > 0){ 
      console.log(results); 
     } 
     else{ 
      alert('nope'); 
     } 
    } 
    else{ 
     alert('nope'); 
    } 
}); 

如何指定我只想要類型street_address?

回答

0

使用componentRestrictions參數,並指定你的street_address組件是這樣的:

geocoder.geocode({ 
    componentRestrictions:{ 
     street_address:'Avenue of The Stars', 
    } 
}, ...) 

你省略address PARAM因爲你所查詢的特定street_address組件的方式。

您也可以將一個或任意數量的組件和address參數:

geocoder.geocode({ 
    address:'stars', 
    componentRestrictions:{ 
     country:'United States', 
     city:'Los Angeles', 
    } 
}, ...) 

地理編碼這樣將搜索字符串包括「明星」的任何組件類型。

您可以在這裏找到其他可查詢組件列表:https://developers.google.com/maps/documentation/geocoding/#Types