Google hosts API, receives user addresses

I struggled with the Google Places API, I need to use the API.

I used autoComplete and the placePicker API is just fine, for some reason the address API is not working.

I tried viewing this https://developers.google.com/android/reference/com/google/android/gms/identity/intents/Address
but I could not figure out how to use addApi() for the API.

If someone can provide some sample code or something to get me started, he would be much appreciated.

Thanks in advance.

+5
android google-places-api
source share
1 answer

To add an API, you need to add this option:

  Address.AddressOptions options = new Address.AddressOptions(AddressConstants.Themes.THEME_LIGHT); mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Address.API, options) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); 

Then you can request the address:

 UserAddressRequest request = UserAddressRequest.newBuilder().build(); Address.requestUserAddress(mGoogleApiClient, request, REQUEST_CODE); 

And then you get the result:

 @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CODE: switch (resultCode) { case Activity.RESULT_OK: UserAddress userAddress = UserAddress.fromIntent(data); //DO SOMETHING break; case Activity.RESULT_CANCELED: break; default: //NO ADDRESS break; } break; } } 

And add this to your gradle:

  compile 'com.google.android.gms:play-services-identity:8.1.0' 
0
source share

All Articles