请帮忙。我尝试实施地方选择器获取城市名称和国家。但它仍然没有结果。如何从Android Place picker中获取城市和国家?
在NewItemFragment
mAddLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO QIBEE Insert
PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
try {
Intent intent = intentBuilder.build(getActivity());
getActivity().startActivityForResult(intent,REQ_CODE);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
在App.java
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(getApplicationContext(), Locale.ENGLISH);
try {
addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0) {
App.getInstance().setLat(latitude);
App.getInstance().setLng(longitude);
sharedPref.edit().putString(getString(R.string.settings_account_lat), Double.toString(this.getLat())).apply();
sharedPref.edit().putString(getString(R.string.settings_account_lng), Double.toString(this.getLng())).apply();
App.getInstance().setArea(addresses.get(0).getAdminArea());
App.getInstance().setCity(addresses.get(0).getLocality());
App.getInstance().setCountry(addresses.get(0).getCountryName());
你能告诉我们你迄今为止所尝试过的,以便我们可以帮助一点。 –
https://stackoverflow.com/help/how-to-ask – gaurang
你需要改变你的代码。但是你没有表现出来,所以我们可以提供帮助。 –