我正在使用Google Maps API处理Android应用,将位置信息作为JSON返回。但是,当我按纬度和经度搜索时,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"
}
答案 0 :(得分:0)
看起来这是此API可以访问的数据的限制,并且无论您是否获得坐标数据,它基本上都会受到影响。
测试Sumaya,它显示结果: https://maps.googleapis.com/maps/api/geocode/json?address=sumaya
但是,情况与你问题中的网址相同,它显示的是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对给定位置的数据量。