我正在使用地点选择器的意图来获取该地点。现在我想将地址以国家、城市、密码、州分开的形式保存。如何从地点选择器的地址中获取所有这些信息?
代码:
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());
}
}
}
}
这就是我实现地点选择器并在ActivityResult 上获取地点名称的方式。我可以使用反向地理编码或其他方法来获得这个吗?任何人都可以帮我解决这个问题吗?谢谢你。