谷歌地方api应该只返回地址

Pau*_* T. 5 iphone google-maps google-maps-api-3 ios

我使用这个 url 通过 Get 请求获取地址:https : //maps.googleapis.com/maps/api/place/autocomplete/json?input=Nov&key=MyKet&types= address

但有时我只得到没有房子的街道,有时我什至得到城市(如果俄语中的 input=Minsk:https : //maps.googleapis.com/maps/api/place/autocomplete/json? input=%D0%9C% D0 %98%D0%9D%D0%A1%D0%9A&key=MyKey&types=address )

但是我只想得到有房子的街道,因为我正在编写出租车应用程序并且我只需要完整的地址,如果用户只选择了街道是不够的。

所以如果我从谷歌得到Proletarsk street 25, Bern, Switzerland- 没关系,但如果我从谷歌得到 Proletarsk street, Bern, Switzerland- 那就不好了。

当我从谷歌得到街道和地址的回复时,它总是返回相同的类型

types =     (
        route,
        geocode
    );
Run Code Online (Sandbox Code Playgroud)

所以我什至无法区分返回值是街道还是完整地址。

你能给我任何建议吗?

kah*_*aho 2

根据您描述的用例,听起来您使用了错误的 API。

如果您有地址并且希望 Google 地图为您解析它并返回额外信息,您应该使用地理编码 API 。您可以确定结果是否包含 a street_number,以便判断结果是否包含完整地址。例如: https:
//maps.googleapis.com/maps/api/geocode/json?address
=1600+Amphitheatre+Parkway,+Mountain+View,+CA 会给您这样的结果:

    {
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "1600",
               "short_name" : "1600",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Amphitheatre Parkway",
               "short_name" : "Amphitheatre Pkwy",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Mountain View",
               "short_name" : "Mountain View",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Santa Clara County",
               "short_name" : "Santa Clara County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "California",
               "short_name" : "CA",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4223455,
               "lng" : -122.0841893
            },
            "location_type" : "ROOFTOP",
            "viewp.....
Run Code Online (Sandbox Code Playgroud)

它给了你一个street_number,所以你可以知道它是一个完整的地址。