使用地址搜索时缺少administrative_area_level_2,但使用latlng

时间:2017-07-26 12:06:57

标签: javascript google-maps google-maps-api-3

为什么我在搜索" Karup"时没有得到administrative_area_level_2(" Viborg")。 (不使用latlng查询)?

当搜索地址时(例如上面的例子),是否有办法使地址编码器不跳过例如结果集中的administrative_area_level_2?

示例:

寻找" Karup"在丹麦使用这个: http://maps.googleapis.com/maps/api/geocode/json?components=country:DK&address=Karup&language=da

返回以下有趣信息(请参阅下面的结果-1以获取完整结果集)...注意这里缺少" administrative_area_level_2(" Viborg"):

"long_name" : "Karup",
"short_name" : "Karup",
"types" : [ "locality", "political" ]

"long_name" : "Danmark",
"short_name" : "DK",
"types" : [ "country", "political" ]

"location" : {"lat" : 56.307765, "lng" : 9.1676629 }

然后,如果我在第一个结果中使用位置的latlng值,如下所示:

https://maps.googleapis.com/maps/api/geocode/json?latlng=56.307765,9.1676629&language=da

(请参阅下面的结果-2以获得完整的结果集),然后我得到了这些有趣的部分(以及其他部分):

"long_name" : "Karup",
"short_name" : "Karup",
"types" : [ "locality", "political" ]

"long_name" : "Viborg",
"short_name" : "Viborg",
"types" : [ "administrative_area_level_2", "political" ]

"long_name" : "Danmark",
"short_name" : "DK",
"types" : [ "country", "political" ]

结果-1:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Karup",
               "short_name" : "Karup",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Danmark",
               "short_name" : "DK",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "7470",
               "short_name" : "7470",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "7470 Karup, Danmark",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 56.41066989999999,
                  "lng" : 9.320741199999999
               },
               "southwest" : {
                  "lat" : 56.2160131,
                  "lng" : 9.022918599999999
               }
            },
            "location" : {
               "lat" : 56.307765,
               "lng" : 9.1676629
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 56.41066989999999,
                  "lng" : 9.320741199999999
               },
               "southwest" : {
                  "lat" : 56.2160131,
                  "lng" : 9.022918599999999
               }
            }
         },
         "place_id" : "ChIJ7wqM9R3CS0YRNUycN6M8YeY",
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}

结果-2(来自latlng且只有address_components数组中的第一项):

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "5A",
               "short_name" : "5A",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Genvej",
               "short_name" : "Genvej",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Karup J",
               "short_name" : "Karup J",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "Karup",
               "short_name" : "Karup",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Viborg",
               "short_name" : "Viborg",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Danmark",
               "short_name" : "DK",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "7470",
               "short_name" : "7470",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Genvej 5A, 7470 Karup J, Danmark",
         "geometry" : {
            "location" : {
               "lat" : 56.30788,
               "lng" : 9.167926999999999
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 56.30922898029149,
                  "lng" : 9.1692759802915
               },
               "southwest" : {
                  "lat" : 56.3065310197085,
                  "lng" : 9.166578019708496
               }
            }
         },
         "place_id" : "ChIJFRksv_7BS0YRxyN0NOqp11I",
         "types" : [ "street_address" ]
      },

0 个答案:

没有答案