How to parse the address from Google Places GeoDataApi for Android, (address_components are missing)

We use the forecast for the Google Places API, similar to the one in the sample application. When choosing a result, we get details for the predicted location using:

Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId); 

This works great, my problem is that the result only contains the string address.

When using the JS version of the API, the result contains the following:

 "address_components" : [ { "long_name" : "522", "short_name" : "522", "types" : [ "street_number" ] }, { "long_name" : "Overtoom", "short_name" : "Overtoom", "types" : [ "route" ] }, { "long_name" : "Amsterdam-West", "short_name" : "Amsterdam-West", "types" : [ "sublocality_level_1", "sublocality", "political" ] }, { "long_name" : "Amsterdam", "short_name" : "Amsterdam", "types" : [ "locality", "political" ] }, { "long_name" : "Amsterdam", "short_name" : "Amsterdam", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Noord-Holland", "short_name" : "NH", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Nederland", "short_name" : "NL", "types" : [ "country", "political" ] }, { "long_name" : "1054", "short_name" : "1054", "types" : [ "postal_code_prefix", "postal_code" ] } ], 

But the above information inside address_components missing when using the API on Android. How to get this information on Android using Google APIs?

+6
source share
1 answer

Sorry, the answer is "you can not."

Google does not provide structured response data for implementing this API on Android.

You can try to parse the address text, but according to my answer to the related post , this is far from trivial:

  • You understand the clever way to parse this line. Unfortunately, the actual structure of the street / suburb / city / province does not correspond in different areas (for example, in Cape Town in South Africa, the supply structure in Johannesburg in South Africa). So your parsing rules should be very smart.
  • You are using a different Google API. The JavaScript API provides structured data for the corresponding call. Unfortunately, Google recommends against using this technique.

My colleague registered this issue with Google:

+7
source

All Articles