Google将API放置为不返回地址组件

时间:2016-11-11 15:55:17

标签: google-places-api google-places

我的计划正在尝试根据某些文字确定城市,州和国家/地区,例如" New york yankee stadium"我想去美国纽约州纽约市。我正在使用Google Places API执行此操作。根据文档,API应返回地址组件https://developers.google.com/places/web-service/details的列表。但是,现在它只返回格式化地址" 1 E 161st St,Bronx,NY 10451,United States"。

这是我的网络服务网址 https://maps.googleapis.com/maps/api/place/textsearch/json?key=MY_KEY&query=new%20york%20yankee%20stadium

如果我没有写出正确的查询或参数,任何熟悉google place API的人都可以通知我吗?

{
   "html_attributions" : [],
   "results" : [
      {
         "formatted_address" : "1 E 161st St, Bronx, NY 10451, United States",
         "geometry" : {
            "location" : {
               "lat" : 40.82964260000001,
               "lng" : -73.9261745
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 40.83279975,
                  "lng" : -73.92236575000001
               },
               "southwest" : {
                  "lat" : 40.82643674999999,
                  "lng" : -73.93052034999999
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "3d78036d61d35f48650bda737226432b57d82511",
         "name" : "Yankee Stadium",
         "opening_hours" : {
            "open_now" : true,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 540,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/101696810905045719819/photos\"\u003eYankee Stadium\u003c/a\u003e"
               ],
               "photo_reference" : "CoQBdwAAAIxmCLrNS_XZ2FcJqVvRVtBUlNYMBVTVKppOWBu7sICj2q70cqJARBoJlTcZpydbMTzURKWWMVJhYpVCqsnia5pjmDhjvjsTirrEnAc6gvmRYKuUwgewB9Re--FulXzXZ5DY3P9fkwIwuc4U9BJVbqHD5O-N6SbbHcqn4XHUj_OdEhCoNPZ3kiNJhxOCGdYG5O4DGhTqVfUjdq7JzasqYATvQxkL1-H3xg",
               "width" : 1242
            }
         ],
         "place_id" : "ChIJcWnnWiz0wokRCB6aVdnDQEk",
         "rating" : 4.4,
         "reference" : "CmRRAAAA5dHiw1YmLxW60_jITBZjMiUs48L4aVUqlPnPDpN_ySa7rw8kPp04WWk0qf8mG-kkMFSNzh39lP0YwfynW54tLcY4s_EYbAPvNWTMe6wXHm_FJiVbI0Lfenyxz4yOTzunEhDgI64EWoXkQe9k45y6qP3-GhSVSdCMPPZA3joFbnYGV-bqo2e0lw",
         "types" : [ "stadium", "point_of_interest", "establishment" ]
      }
   ],
   "status" : "OK"
}

1 个答案:

答案 0 :(得分:0)

这是一个两步过程,首先搜索并从Google地方搜索服务获取place_id,

使用返回的place_id并通过另一个调用传递它以接收各个地址组件

https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJcWnnWiz0wokRCB6aVdnDQEk&key=

executeUserAddressFlow(request: any): any {           
       Start timer here ---->
        return this.http.post(this.Url, req, { headers: sampleHeader })
            .map(
            res => res.json(),
    stop somewhere here ----->
            error => error
            );
    }