谷歌地图api返回空结果



我正在开发一款Android应用程序,使用Google Maps API将位置信息返回为JSON。然而,当我按纬度和经度搜索时,谷歌地图API有时会返回NO结果。为了确保我没有做错什么,我搜索了像这个一样的城市"idhna"

https://maps.googleapis.com/maps/api/geocode/json?address=idhna&key=XXXXXXXXXXXXXXXXXX

它返回

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Idhna",
               "short_name" : "Idhna",
               "types" : [ "locality", "political" ]
            }
         ],
         "formatted_address" : "Idhna",
         "geometry" : {
            "location" : {
               "lat" : 31.557252,
               "lng" : 34.979243
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 31.5667594,
                  "lng" : 34.9952504
               },
               "southwest" : {
                  "lat" : 31.5477436,
                  "lng" : 34.9632356
               }
            }
         },
         "place_id" : "ChIJjfxiM8TuAhURpQKxXGq5lDo",
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}

但是当我从结果中复制纬度和经度并尝试搜索时

https://maps.googleapis.com/maps/api/geocode/json?latlng=31.557252,34.979243&key=XXXXXXXXXXXXXXXXXXXXXXXXX

结果是

{
   "results" : [],
   "status" : "ZERO_RESULTS"
}

这似乎是这个API可以访问的数据的限制,无论您是否获得坐标数据,基本上都是命中或未命中的。

对Sumaya进行测试,结果如下:https://maps.googleapis.com/maps/api/geocode/json?address=sumaya

然而,情况与您问题中的url相同,它没有显示lat/lon:的结果

https://maps.googleapis.com/maps/api/geocode/json?latlng=31.523946,34.968806

作为一个测试,我尝试了附近的边境城市Beit Guvrin:

https://maps.googleapis.com/maps/api/geocode/json?address=BeitGuvrin

返回的坐标:

"location_type" : "GEOMETRIC_CENTER",
            "viewport" : {
               "northeast" : {
                  "lat" : 32.1298801302915,
                  "lng" : 34.8555745
               },

它从lat/lon:返回有效结果

https://maps.googleapis.com/maps/api/geocode/json?latlng=32.1298801302915,34.8555745

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "3-41",
               "short_name" : "3-41",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "HaNevi'im Street",
               "short_name" : "HaNevi'im St",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Ramat Hasharon",
               "short_name" : "Ramat Hasharon",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Tel Aviv District",
               "short_name" : "Tel Aviv District",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Israel",
               "short_name" : "IL",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "HaNevi'im St 3-41, Ramat Hasharon, Israel",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 32.130616,
                  "lng" : 34.855772
               },
               "southwest" : {
                  "lat" : 32.129476,
                  "lng" : 34.853687
               }
            },
            "location" : {
               "lat" : 32.1297776,
               "lng" : 34.8554613
            },
            "location_type" : "RANGE_INTERPOLATED",
            "viewport" : {
               "northeast" : {
                  "lat" : 32.1313949802915,
                  "lng" : 34.8560784802915
               },
               "southwest" : {
                  "lat" : 32.1286970197085,
                  "lng" : 34.8533805197085
               }
            }
         },
         "place_id" : "EjLXlNeg15HXmdeQ15nXnSAzLTQxLCDXqNee16og15TXqdeo15XXnywg15nXqdeo15DXnA",
         "types" : [ "street_address" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Ramat Hasharon",
               "short_name" : "Ramat Hasharon",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Tel Aviv District",
               "short_name" : "Tel Aviv District",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Israel",
               "short_name" : "IL",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Ramat Hasharon, Israel",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 32.158889,
                  "lng" : 34.86803
               },
               "southwest" : {
                  "lat" : 32.11189,
                  "lng" : 34.795732
               }
            },
            "location" : {
               "lat" : 32.137793,
               "lng" : 34.840278
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 32.158889,
                  "lng" : 34.86803
               },
               "southwest" : {
                  "lat" : 32.11189,
                  "lng" : 34.795732
               }
            }
         },
         "place_id" : "ChIJdWZI5UtIHRUREKFBBFqVWY0",
         "types" : [ "locality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Ezor Tel Aviv",
               "short_name" : "Ezor Tel Aviv",
               "types" : [ "administrative_area_level_3", "political" ]
            },
            {
               "long_name" : "Israel",
               "short_name" : "IL",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Ezor Tel Aviv, Israel",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 32.2021482,
                  "lng" : 34.86803
               },
               "southwest" : {
                  "lat" : 32.0292531,
                  "lng" : 34.7425159
               }
            },
            "location" : {
               "lat" : 32.1128462,
               "lng" : 34.8072165
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 32.2021482,
                  "lng" : 34.86803
               },
               "southwest" : {
                  "lat" : 32.0292531,
                  "lng" : 34.7425159
               }
            }
         },
         "place_id" : "ChIJFYqCjvhIHRURfMkU1A0mkV0",
         "types" : [ "administrative_area_level_3", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Tel Aviv District",
               "short_name" : "Tel Aviv District",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Israel",
               "short_name" : "IL",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Tel Aviv District, Israel",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 32.202148,
                  "lng" : 34.8756378
               },
               "southwest" : {
                  "lat" : 32.0165529,
                  "lng" : 34.7425159
               }
            },
            "location" : {
               "lat" : 32.0929075,
               "lng" : 34.8072165
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 32.202148,
                  "lng" : 34.8756378
               },
               "southwest" : {
                  "lat" : 32.0165529,
                  "lng" : 34.7425159
               }
            }
         },
         "place_id" : "ChIJsTJP_rZLHRURQNXiBl_Sf9s",
         "types" : [ "administrative_area_level_1", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Israel",
               "short_name" : "IL",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Israel",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 33.33280500000001,
                  "lng" : 35.896244
               },
               "southwest" : {
                  "lat" : 29.4906463,
                  "lng" : 34.2673871
               }
            },
            "location" : {
               "lat" : 31.046051,
               "lng" : 34.851612
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 33.33280500000001,
                  "lng" : 35.896244
               },
               "southwest" : {
                  "lat" : 29.4906463,
                  "lng" : 34.2673871
               }
            }
         },
         "place_id" : "ChIJi8mnMiRJABURuiw1EyBCa2o",
         "types" : [ "country", "political" ]
      }
   ],
   "status" : "OK"
}

我还测试了Keidar,它成功地显示了从地址查询返回的坐标的结果。

因此,它基本上是命中或未命中的,这取决于API在给定位置拥有多少数据。

相关内容

  • 没有找到相关文章

最新更新