【问题标题】:Geocoder API return only street addressesGeocoder API 仅返回街道地址
【发布时间】:2013-10-18 15:39:08
【问题描述】:

我从 Google 的地理编码器 API 开始,我只想返回 street_address 的 location_type。

唯一的问题是我不知道该具体要求谁。这是我现在的代码:

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 类型?

【问题讨论】:

    标签: javascript google-geocoder


    【解决方案1】:

    使用componentRestrictions 参数并像这样指定您的street_address 组件:

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

    这样您就省略了address 参数,因为您正在查询特定的street_address 组件。

    您还可以组合一个或任意数量的组件和address参数:

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

    这样,Geocode 将搜索包含字符串“stars”的任何组件类型。

    您可以在此处找到其他可查询组件的列表:https://developers.google.com/maps/documentation/geocoding/#Types

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多