Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Built in Place Picker in Android.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.08k
    Comment on it

    Android has now a built in Place picker, where user can pick the places. Developer can only send an intent and get result in OnActivityResult.

    Requirements -Google play service greater than 7.

    public void onPickButtonClick(View v) {
        // Construct an intent for the place picker
        try {
            PlacePicker.IntentBuilder intentBuilder =
                new PlacePicker.IntentBuilder();
            Intent intent = intentBuilder.build(this);
            // Start the intent by requesting a result,
            // identified by a request code.
            startActivityForResult(intent, REQUEST_PLACE_PICKER);
    
        } catch (GooglePlayServicesRepairableException e) {
            // ...
        } catch (GooglePlayServicesNotAvailableException e) {
            // ...
        }
    }
    
    @Override
    protected void onActivityResult(int requestCode,
            int resultCode, Intent data) {
    
        if (requestCode == REQUEST_PLACE_PICKER
            && resultCode == Activity.RESULT_OK) {
    
            // The user has selected a place. Extract the name and address.
            final Place place = PlacePicker.getPlace(data, this);
    
            final CharSequence name = place.getName();
            final CharSequence address = place.getAddress();
            String attributions = PlacePicker.getAttributions(data);
            if (attributions == null) {
                attributions = "";
            }
    
            mViewName.setText(name);
            mViewAddress.setText(address);
            mViewAttributions.setText(Html.fromHtml(attributions));
    
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
    
    

    Reference : https://developers.google.com/places/android-api/

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: