检测当前位置并填充我的活动

时间:2016-11-09 11:58:26

标签: android reverse-geocoding currentlocation

我的问题是我有一个多个EditText的活动,如街道,地标,位置,城市等。在位置EditText我按下一个按钮来获取当前用户位置并在各个EditText中填写用户地址。 enter image description here 注意:我成功获取当前位置并填充整个EditText位置,但我想在Street EditText中添加街道号码,在City EditText中添加城市等

1 个答案:

答案 0 :(得分:1)

您可以使用Official Documentation开始并找到许多"反向地理编码"像这样:

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());

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 city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName(); //

来自here