6

Google Places API can return details about a particular place, given its ID:

Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)

The data returned in the callback implements the Place interface, providing access to the address as a comma-separated string using method:

Place.getAddress()

Parsing this string into fields for street, suburb, province, town etc is not reliable as string is not in a consistent format:

  • Ranelagh Rd, Cape Town, South Africa (street, suburb, country)
  • 1st Ave, Kenilworth, Cape Town, 7708, South Africa (street, suburb, town, post code, country)
  • SW 23rd Terrace, Cape Coral, FL 33991, USA (street, town, post code, country)

Is there a reliable way to get parsed address info from Google?

Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
  • 1
    I think because there are different place types, so the place format are different, also different countries has slightly different kind of place format. Or you can use the [Address](http://developer.android.com/reference/android/location/Address.html) class, it has `getCountryName()` and `getPostalCode()` methods etc. – ztan Oct 19 '15 at 18:09
  • @ztan any idea how to populate `Address` by reverse geocoding a lat/lng pair? I see you have a fair amount of Google Maps experience. – Richard Le Mesurier Oct 19 '15 at 18:37
  • You can first make a `Geocoder` object by doing `Geocoder geocoder = new Geocoder(this, Locale.getDefault());`, then call `addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);` You put `1` here, so that it will only return 1 result, you can see [this documentation](http://developer.android.com/training/location/display-address.html) for more details. – ztan Oct 19 '15 at 18:46
  • @RichardLeMesurier Have you found solution for this? – selva_pollachi Dec 30 '18 at 17:28
  • 1
    @selva_pollachi best thing we found was to write a server API that calls the cloud rest functions and parses the fields out. So the mobile device does not call Google directly, but via our server. The experience is actually better this way because we can augment the results with app-specific info. – Richard Le Mesurier Dec 31 '18 at 07:30

0 Answers0