Friday, 1 September 2017

Google Place Picker LIb


Java Class

private LocationManager service;

@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_address, container, false);

    service = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
   
    return view;
}


edtsubrub.setOnClickListener(this);

case R.id.map:
    if (!service.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        showSettingsAlert();
    } else {
        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
        try {
            startActivityForResult(builder.build((AppCompatActivity) getActivity()), PLACE_PICKER_REQUEST);
        } catch (GooglePlayServicesRepairableException e) {
            e.printStackTrace();
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }


public void showSettingsAlert() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    alertDialog.setTitle("GPS settings");
    alertDialog.setMessage("Location is not enabled. Do you want to go to settings menu?");
    alertDialog.setPositiveButton("Settings",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(
                            Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    getActivity().startActivity(intent);
                }
            });
    alertDialog.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
    alertDialog.show();
}




case R.id.edtsubrub:
    try {
        Intent intent =
                new PlaceAutocomplete
                        .IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                        .build(getActivity());
        startActivityForResult(intent, 1);
    } catch (GooglePlayServicesRepairableException e) {
    } catch (GooglePlayServicesNotAvailableException e) {
    }
    break;
default:



No comments:

Post a Comment