Search code examples
androidlocationgoogle-places-api

Retrieving the exact current address with Google Places API


I've used a bit of a hack to retrieve my exact current place address but it's not a very robust solution because I'm working with Google Places API and I would rather much work with Place Objects vs. Strings where I parse the address from there.

So I decided to try and find my current address via Places API using the algorithm provided on their site that finds the "most likely" place to the user's current location. (https://developers.google.com/places/android-api/current-place)

PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);

result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {

@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
    for (PlaceLikelihood placeLikelihood : likelyPlaces) {
      Log.i(TAG, String.format("Place '%s' has likelihood: %g",
      placeLikelihood.getPlace().getName(),
      placeLikelihood.getLikelihood()));
    }
   likelyPlaces.release();
 }
});

So I tried that out and the output was:

Place 'XXXXXXX' has likelihood: 0.600000
Place 'MyStreetAddress' has likelihood: 0.0500000
Place 'YYYYYYY' has likelihood: 0.00000
Place 'ZZZZZZZ' has likelihood: 0.00000

The first, "most likely" recommendation is about 6 km away from my current location and the second recommendation was my exact street address. Is there anyway to make it more exact or provide some sort of filter so it can only recommend certain specific addresses versus general places like "Thames River" or "Telus Stadium"?


Solution

  • I found out you need to turn your GPS to "High Accuracy" mode. All is fixed.