我正在研究Android中的反向地理编码功能。
当我使用Google API调用的地理编码器类进行getFromLocation(0, 0, 1)
时,它会返回ZERO RESULTS
,地址长度为零。
但是,例如当我在网络上访问谷歌地图时,我右键点击位置0,0,它说"大西洋"。当我在Android中的Google地图应用中放置一个图钉时,这也有效。
有没有办法让大西洋"或者类似于坐标0,0的编程?当我说0,0时它也适用于海中间的其他坐标。
答案 0 :(得分:2)
是的,有一种方法可以获得与坐标对应的海洋名称。我所做的是使用谷歌地图Javascript API然后根据请求我添加了result_type = natural_feature,它代表地址类型中的水体和沙漠体。添加它将返回坐标中最近的水体。可以使用Webview将Javascript集成到Android上。
以下是我对两个请求的请求和回复:
第一个请求类似于getFromLocation(0,0,1)
请求:
https://maps.googleapis.com/maps/api/geocode/json?latlng=0,0&key=YOUR_API_KEY
响应:
{
"results" : [],
"status" : "ZERO_RESULTS"
}
对于下一个使用natural_feature的请求。
请求:
响应:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Atlantic Ocean",
"short_name" : "Atlantic Ocean",
"types" : [ "natural_feature", "establishment" ]
}
],
"formatted_address" : "Atlantic Ocean",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 68.6187515,
"lng" : 20
},
"southwest" : {
"lat" : -83.0204773,
"lng" : -83.21609509999999
}
},
"location" : {
"lat" : -14.5994134,
"lng" : -28.6731465
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 68.6187515,
"lng" : 20.0000001
},
"southwest" : {
"lat" : -83.0204773,
"lng" : -83.21609509999999
}
}
},
"place_id" : "ChIJ_7hu48qBWgYRT1MQ81ciNKY",
"types" : [ "natural_feature", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Equator",
"short_name" : "Equator",
"types" : []
}
],
"formatted_address" : "Equator",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 0,
"lng" : 180
},
"southwest" : {
"lat" : 0,
"lng" : -180
}
},
"location" : {
"lat" : 0,
"lng" : 0
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 0.00134898029150203,
"lng" : 180
},
"southwest" : {
"lat" : -0.00134898029150203,
"lng" : -180
}
}
},
"place_id" : "ChIJ9f-dgJ14AHARMp45pd8HMhs",
"types" : []
},
{
"address_components" : [
{
"long_name" : "Virgo",
"short_name" : "Virgo",
"types" : []
}
],
"formatted_address" : "Virgo",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 14.3954258,
"lng" : 47.853012
},
"southwest" : {
"lat" : -22.9842321,
"lng" : -5.6577015
}
},
"location" : {
"lat" : -4.294403099999999,
"lng" : 21.0976553
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 14.3954258,
"lng" : 47.853012
},
"southwest" : {
"lat" : -22.9842321,
"lng" : -5.6577015
}
}
},
"place_id" : "ChIJ3dT5sNUyHxoRJjQnMK1jABU",
"types" : []
}
],
"status" : "OK"
}