我正在使用地理编码器从纬度和经度获取地址,但我获得的JSON不是非常全面,例如,我只获得了胡同和城市,但我无法获得街道名称或区域名称。肯定有其他方法来实现类似的东西,但更全面。这是我的代码:
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(context, Locale.getDefault());
try {
addresses = geocoder.getFromLocation(currentLatLng.latitude, currentLatLng.longitude, 1);
String text = addresses.get(0).getThoroughfare();
} catch (IOException e) {
e.printStackTrace();
}发布于 2017-08-20 00:33:59
试试这个:
addresses = geocoder.getFromLocation(Latitude, Longitude,1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String address1 = addresses.get(0).getAddressLine(1); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String address2 = addresses.get(0).getAddressLine(2); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String address3 = addresses.get(0).getAddressLine(3); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()发布于 2017-08-21 08:38:53
您是否考虑过将Geocoding web service作为替代方案?
示例:
GET https://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Pkwy",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
.
.
.https://stackoverflow.com/questions/45773174
复制相似问题