如何从 Place Picker 的地址获取值?
How can I get values from address of Place Picker?
我想从 android 中的 Place Picker 地址获取值并将其分成不同的 EditText,就像我想在 PineCodeEditText
上设置密码,在 CountryEditText
上设置国家/地区,设置状态 StateEditText
等等。我的地址是
10, Mothorowala Rd, Jagdamba Colony, Dharmpur, Ajabpur Kalan,
Dehradun, Uttarakhand 248001, India
我用过的地方
Place place = PlacePicker.getPlace(data,this);
String address = String.format(String.valueOf(place.getAddress()));
在此之前,我使用了 Split 函数,但它给出了 indexOutOfBoundException
。
欢迎任何建议,谢谢。
可以从Place
对象获取经纬度坐标,然后使用GeoCoder
获取地址对象,可以单独获取需要的数据。
LatLng coordinates = place.getLatLng(); // Get the coordinates from your place
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(
coordinates.latitude,
coordinates.longitude,
1); // Only retrieve 1 address
Address address = addresses.get(0);
String countryCode = address.getCountryCode();
String countryName = address.getCountryName();
我想从 android 中的 Place Picker 地址获取值并将其分成不同的 EditText,就像我想在 PineCodeEditText
上设置密码,在 CountryEditText
上设置国家/地区,设置状态 StateEditText
等等。我的地址是
10, Mothorowala Rd, Jagdamba Colony, Dharmpur, Ajabpur Kalan, Dehradun, Uttarakhand 248001, India
我用过的地方
Place place = PlacePicker.getPlace(data,this);
String address = String.format(String.valueOf(place.getAddress()));
在此之前,我使用了 Split 函数,但它给出了 indexOutOfBoundException
。
欢迎任何建议,谢谢。
可以从Place
对象获取经纬度坐标,然后使用GeoCoder
获取地址对象,可以单独获取需要的数据。
LatLng coordinates = place.getLatLng(); // Get the coordinates from your place
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(
coordinates.latitude,
coordinates.longitude,
1); // Only retrieve 1 address
Address address = addresses.get(0);
String countryCode = address.getCountryCode();
String countryName = address.getCountryName();