com.google.android.gms.location.places.PlaceLikelihood Java Examples

The following examples show how to use com.google.android.gms.location.places.PlaceLikelihood. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void detectNearbyPlaces() {
    if( !checkLocationPermission() ) {
        return;
    }

    Awareness.SnapshotApi.getPlaces(mGoogleApiClient)
            .setResultCallback(new ResultCallback<PlacesResult>() {
                @Override
                public void onResult(@NonNull PlacesResult placesResult) {
                    Place place;
                    for( PlaceLikelihood placeLikelihood : placesResult.getPlaceLikelihoods() ) {
                        place = placeLikelihood.getPlace();
                        Log.e("Tuts+", place.getName().toString() + "\n" + place.getAddress().toString() );
                        Log.e("Tuts+", "Rating: " + place.getRating() );
                        Log.e("Tuts+", "Likelihood that the user is here: " + placeLikelihood.getLikelihood() * 100 + "%");
                    }
                }
            });
}
 
Example #2
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
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();
        }
    });
}
 
Example #3
Source File: SnapshotApiActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Get the nearby places using Snapshot apis. We are going to display only first 5 places to the user in the list.
 */
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
private void getPlace() {
    //noinspection MissingPermission
    Awareness.SnapshotApi.getPlaces(mGoogleApiClient)
            .setResultCallback(new ResultCallback<PlacesResult>() {
                @Override
                public void onResult(@NonNull final PlacesResult placesResult) {
                    if (!placesResult.getStatus().isSuccess()) {
                        Toast.makeText(SnapshotApiActivity.this, "Could not get places.", Toast.LENGTH_LONG).show();
                        return;
                    }

                    //get the list of all like hood places
                    List<PlaceLikelihood> placeLikelihoodList = placesResult.getPlaceLikelihoods();

                    // Show the top 5 possible location results.
                    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.current_place_container);
                    linearLayout.removeAllViews();
                    if (placeLikelihoodList != null) {
                        for (int i = 0; i < 5 && i < placeLikelihoodList.size(); i++) {
                            PlaceLikelihood p = placeLikelihoodList.get(i);

                            //add place row
                            View v = LayoutInflater.from(SnapshotApiActivity.this).inflate(R.layout.row_nearby_place, linearLayout, false);
                            ((TextView) v.findViewById(R.id.place_name)).setText(p.getPlace().getName());
                            ((TextView) v.findViewById(R.id.place_address)).setText(p.getPlace().getAddress());
                            linearLayout.addView(v);
                        }
                    } else {
                        Toast.makeText(SnapshotApiActivity.this, "Could not get nearby places.", Toast.LENGTH_LONG).show();
                    }
                }
            });
}
 
Example #4
Source File: ViewActivity.java    From memoir with Apache License 2.0 4 votes vote down vote up
public void getCurrentLocation() {
    try {
        // On Marshmallow request for permissions first
        if (Build.VERSION.SDK_INT >= 23) {
            if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
                        PERMISSION_ACCESS_FINE_LOCATION);
            } else {
                return;
            }
            if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},
                        PERMISSION_ACCESS_COARSE_LOCATION);
            } else {
                return;
            }
        }

        PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace(mGoogleApiClient, null);
        result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
            @Override
            public void onResult(@NonNull PlaceLikelihoodBuffer likelyPlaces) {
                Place place = null;
                float max = 0;
                for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                    float likelihood = placeLikelihood.getLikelihood();
                    if (likelihood > max) {
                        place = placeLikelihood.getPlace();
                        max = placeLikelihood.getLikelihood();
                    }
                }
                if (place == null) {
                    Toast.makeText(getApplicationContext(), R.string.note_location_unable, Toast.LENGTH_SHORT).show();
                } else {
                    note.setLocation(place);
                    refreshLayout();
                }
                likelyPlaces.release();
            }
        });
    } catch (Exception ex) {
        Toast.makeText(getApplicationContext(), R.string.note_location_unable, Toast.LENGTH_SHORT).show();
    }
}