私は場所を取得するためにプレイスピッカーの意図を使用しています。今、私は住所を国、都市、ピンコード、州のように区切って保存したいと思います。どのように私は場所のピッカーのアドレスからすべてを得ることができますか?場所ピッカーの住所から国、都市を取得するにはどうすればよいですか?
コード:
public class NameOfBusinessFragment extends Fragment {
int PLACE_PICKER_REQUEST = 1;
int RESULT_OK = -1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
EditText category,location;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_name_of_business,
container, false);
location = (EditText)view.findViewById(R.id.location);
location.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
startActivityForResult(builder.build(getActivity()), PLACE_PICKER_REQUEST);
}
catch (GooglePlayServicesRepairableException e)
{
Toast.makeText(getActivity(),"ServiceRepaire Exception",Toast.LENGTH_SHORT).show();
}
catch (GooglePlayServicesNotAvailableException e)
{
Toast.makeText(getActivity(),"SeerviceNotAvailable Exception",Toast.LENGTH_SHORT).show();
}
}
});
return view;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, getActivity());
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(getActivity(), toastMsg, Toast.LENGTH_LONG).show();
location.setText(place.getName());
}
}
}
}
これは私が場所ピッカーを実装し、地名をonActivityResult取得する方法です。逆ジオコードなどを使用してこれを取得できますか?誰も私を助けてくれますか?ありがとうございました。
Geocoderは信頼性がありません。ほとんどの場合、nullを返します。 –