【问题标题】:google maps api returns empty result谷歌地图 api 返回空结果
【发布时间】:2015-12-01 23:14:29
【问题描述】:

我正在开发一个使用 Google Maps API 以 JSON 格式返回位置信息的 Android 应用程序。但是,当我按纬度和经度搜索时,Google Maps 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"
}

【问题讨论】:

    标签: android google-api location maps


    【解决方案1】:

    看起来这是此 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
                   },
    

    从纬度/经度返回有效结果:

    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 对给定位置有多少数据。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-10
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    相关资源
    最近更新 更多