private void callPlaceDetectionApi() throws SecurityException { 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(LOG_TAG, String.format("Place '%s' with " + "likelihood: %g", placeLikelihood.getPlace().getName(), placeLikelihood.getLikelihood())); } likelyPlaces.release(); } }); }
private void callPlaceDetectionApi() throws SecurityException { 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(LOG_TAG, String.format("Place '%s' with " + "likelihood: %g", placeLikelihood.getPlace().getName(), placeLikelihood.getLikelihood())); display.setText(placeLikelihood.getPlace().getAddress().toString()); messageSending(placeLikelihood.getPlace().getAddress().toString()); break; } likelyPlaces.release(); } }); }
private void callPlaceDetectionApi2(final String ph_number) throws SecurityException { 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(LOG_TAG, String.format("Place '%s' with " + "likelihood: %g", placeLikelihood.getPlace().getName(), placeLikelihood.getLikelihood())); display.setText(placeLikelihood.getPlace().getAddress().toString()); messageSending_individual(ph_number,placeLikelihood.getPlace().getAddress().toString()); break; } likelyPlaces.release(); } }); }
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(); } }); }
/** * Adds markers for places nearby the device and turns the My Location feature on or off, * provided location permission has been granted. */ private void updateMarkers() { if (mMap == null) { return; } if (mLocationPermissionGranted) { // Get the businesses and other points of interest located // nearest to the device's current location. @SuppressWarnings("MissingPermission") PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi .getCurrentPlace(mGoogleApiClient, null); result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() { @Override public void onResult(@NonNull PlaceLikelihoodBuffer likelyPlaces) { for (PlaceLikelihood placeLikelihood : likelyPlaces) { // Add a marker for each place near the device's current location, with an // info window showing place information. String attributions = (String) placeLikelihood.getPlace().getAttributions(); String snippet = (String) placeLikelihood.getPlace().getAddress(); if (attributions != null) { snippet = snippet + "\n" + attributions; } mMap.addMarker(new MarkerOptions() .position(placeLikelihood.getPlace().getLatLng()) .title((String) placeLikelihood.getPlace().getName()) .snippet(snippet)); } // Release the place likelihood buffer. likelyPlaces.release(); } }); } else { mMap.addMarker(new MarkerOptions() .position(mDefaultLocation) .title(getString(R.string.default_info_title)) .snippet(getString(R.string.default_info_snippet))); } }
/** * 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(); } } }); }
/** * Provides the currently nearby places to the current device location. * * @return Single event of the currently nearby places */ @RequiresPermission("android.permission.ACCESS_FINE_LOCATION") public Single<List<PlaceLikelihood>> getNearbyPlaces() { guardWithApiKey(context, API_KEY_AWARENESS_API); guardWithApiKey(context, API_KEY_PLACES_API); return NearbySingle.create(context); }
public void isAtGasStationAsync(final CurrentPlaceListener currentPlaceListener) { if (!LocationHelper.isLocationPermissionAsked && ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LocationHelper.LOCATION_PERMISSION_REQUEST); Log.e("getting location", "NO PERMISSION"); } PendingResult<PlaceLikelihoodBuffer> places = Places.PlaceDetectionApi .getCurrentPlace(googleApiClient, null); places.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() { @Override public void onResult(PlaceLikelihoodBuffer likelyPlaces) { for (PlaceLikelihood placeLikelihood : likelyPlaces) { if (placeLikelihood.getLikelihood() > LIKELIHOOD_ACCEPTABLE) { List<Integer> types = placeLikelihood.getPlace().getPlaceTypes(); for (int t : types) { if (t == Place.TYPE_GAS_STATION) { lastStation = new Station(placeLikelihood.getPlace()); currentPlaceListener.OnIsAtGasStationResult(lastStation); break; } } } } likelyPlaces.release(); } }); }
private void lokasyonCek(final boolean hepsi, final boolean hastahane, final boolean eczane, final boolean cafe, final boolean ibadethane, final boolean okul, final boolean diger) { PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi .getCurrentPlace(mGoogleApiClient, null); result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() { @Override public void onResult(PlaceLikelihoodBuffer likelyPlaces) { for (PlaceLikelihood placeLikelihood : likelyPlaces) { List types=placeLikelihood.getPlace().getPlaceTypes(); Log.i("liste", String.format("Place '%s' has likelihood: %g", placeLikelihood.getPlace().getName(), placeLikelihood.getLikelihood())); if(hepsi) konumlar.add(placeLikelihood.getPlace().getName().toString()); else{ if(hastahane && (types.contains(Place.TYPE_HOSPITAL) || types.contains(Place.TYPE_DOCTOR) ||types.contains(Place.TYPE_DENTIST) || types.contains(Place.TYPE_VETERINARY_CARE))) konumlar.add(placeLikelihood.getPlace().getName().toString()); if(eczane && types.contains(Place.TYPE_PHARMACY)) konumlar.add(placeLikelihood.getPlace().getName().toString()); if(cafe &&( types.contains(Place.TYPE_CAFE) ||(types.contains(Place.TYPE_RESTAURANT) || types.contains(Place.TYPE_NIGHT_CLUB)))) konumlar.add(placeLikelihood.getPlace().getName().toString()); if(ibadethane && (types.contains(Place.TYPE_MOSQUE) || types.contains(Place.TYPE_CHURCH))) konumlar.add(placeLikelihood.getPlace().getName().toString()); if(okul && (types.contains(Place.TYPE_UNIVERSITY) || types.contains(Place.TYPE_SCHOOL))) konumlar.add(placeLikelihood.getPlace().getName().toString()); if(diger) konumlar.add(placeLikelihood.getPlace().getName().toString()); } } likelyPlaces.release(); veriAdaptoru.notifyDataSetChanged(); } }); }
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(); } }
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION") public static Single<List<PlaceLikelihood>> create(Context context) { return Single.create(new NearbySingle(context)); }
@Override protected List<PlaceLikelihood> unwrap(PlacesResult result) { return result.getPlaceLikelihoods(); }