Getting name of google places API (Place Search) for my current location

2.4k Views Asked by At

I am making an android app, in which I will use the name of current location to search its details over wikipedia. for e.g. If I am in Madame Tussauds, First I ll get the current location coordinates then after reverse geocoding, it's info will be searched over wikipedia and displayed in my app.

I have my current location coordinates but the problem is when I reverse geocode the coordinates, I don't get the place name. for e.g. for coordinates 33.651826, 73.156593, when I reverse geocode, I get Park Road, Pakistan where as the name of the place is COMSATS Institute of Information Technology.

I get COMSATS Institute of Information Technology in Google Places API (Place Search) in Name node. So is there a way I can use Google Places API's name node for my current location name rather than any place search or other features?

Or is there any way I can get the place name using lat lon?

2

There are 2 best solutions below

0
On BEST ANSWER

Define a GoogleApiClient object and then call this method

private void guessCurrentPlace() {
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace( mGoogleApiClient, null );
result.setResultCallback( new ResultCallback<PlaceLikelihoodBuffer>() {
    @Override
    public void onResult( PlaceLikelihoodBuffer likelyPlaces ) {

        PlaceLikelihood placeLikelihood = likelyPlaces.get( 0 );
        String content = "";
        if( placeLikelihood != null && placeLikelihood.getPlace() != null && !TextUtils.isEmpty( placeLikelihood.getPlace().getName() ) )
            content = "Most likely place: " + placeLikelihood.getPlace().getName() + "\n";
        if( placeLikelihood != null )
            content += "Percent change of being there: " + (int) ( placeLikelihood.getLikelihood() * 100 ) + "%";
        mTextView.setText( content );

        likelyPlaces.release();
    }
});
}

Reference: http://code.tutsplus.com/articles/google-play-services-using-the-places-api--cms-23715

0
On

The Places API for Android, introduced in Google Play services 7.0, offers an API around getting the current place using PlaceDetectionApi.getCurrentPlace(). That method uses the user's current location and then returns a list of likely places for the user to be at. You can then use Place.getName() to retrieve the name of the location and display it to the user.

If you want the user to pick a location from around them (rather than choosing the topmost result for them), you can use the Place Picker UI.