@Override protected void onLocationPermissionGranted() { compositeSubscription = new CompositeSubscription(); compositeSubscription.add(reactiveLocationProvider.getPlaceById(placeId) .subscribe(new Action1<PlaceBuffer>() { @Override public void call(PlaceBuffer buffer) { Place place = buffer.get(0); if (place != null) { placeNameView.setText(place.getName()); placeLocationView.setText(place.getLatLng().latitude + ", " + place.getLatLng().longitude); placeAddressView.setText(place.getAddress()); } buffer.release(); } })); }
/** * Updates the local {@link ArrayList} of geofences from the data in the passed list *Uses the place id defined by the API as the geofence object id. * * @param places the placeBuffer result of the getPlaceByid call. */ public void updateGeofencesList(PlaceBuffer places){ mGeofenceList = new ArrayList<>(); if (places==null || places.getCount()==0) return; for (Place place: places){ String placeUid = place.getId(); double latitude = place.getLatLng().latitude; double longitude = place.getLatLng().longitude; //Build a geofence object Geofence geofence = new Geofence.Builder() .setRequestId(placeUid) .setExpirationDuration(GEOFENCE_TIMEOUT) .setCircularRegion(latitude,longitude,GEOFENCE_RADIUS) .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT) .build(); mGeofenceList.add(geofence); } }
public void refreshPlacesData(){ Uri uri = PlacesContract.PlaceEntry.CONTENT_URI; Cursor dataCursor = getContentResolver().query(uri, null, null, null,null,null); if (dataCursor==null||dataCursor.getCount()==0) return; List<String> placeIds = new ArrayList<String>(); while (dataCursor.moveToNext()){ placeIds.add(dataCursor.getString(dataCursor.getColumnIndex(PlacesContract.PlaceEntry.COLUMN_PLACE_ID))); } PendingResult<PlaceBuffer> placeBufferPendingResult = Places.GeoDataApi.getPlaceById(mClient, placeIds.toArray(new String[placeIds.size()])); placeBufferPendingResult.setResultCallback(new ResultCallback<PlaceBuffer>() { @Override public void onResult(@NonNull PlaceBuffer places) { mAdapter.swapPlaces(places); mGeofencing.updateGeofencesList(places); if (mIsEnabled) mGeofencing.registerAllGeofences(); } }); }
@Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { places.release(); return; } try { final Place place = places.get(0); if (Preferences.getInstance(SearchActivity.this).isLogged()) { searchPresenter.getNearStations(place.getLatLng()); places.release(); } else { Intent returnIntent = new Intent(); returnIntent.putExtra(MapFragment.LATITUDE_SEARCH, place.getLatLng().latitude); returnIntent.putExtra(MapFragment.LONGITUDE_SEARCH, place.getLatLng().longitude); places.release(); setResult(Activity.RESULT_OK, returnIntent); finish(); } } catch (Throwable throwable) { resultsRecyclerView.setVisibility(View.GONE); emptyTextView.setVisibility(View.VISIBLE); emptyTextView.setText(getString(R.string.error_generic)); } }
public Observable<PointOfInterest> getCompleteResult(final GoogleApiClient mGoogleApiClient, final String id) { return Observable.create(new Observable.OnSubscribe<PointOfInterest>() { @Override public void call(final Subscriber<? super PointOfInterest> subscriber) { final PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi .getPlaceById(mGoogleApiClient, id); placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() { @Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { places.release(); subscriber.onError(null); } else { subscriber.onNext(PointOfInterest.fromPlace(places.get(0))); places.close(); subscriber.onCompleted(); } } }); } }); }
public Observable<Place> getPlaceByID(final String placeId) { return new Observable<Place>() { @Override protected void subscribeActual(final Observer<? super Place> observer) { Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId) .setResultCallback(new ResultCallback<PlaceBuffer>() { @Override public void onResult(@NonNull PlaceBuffer places) { if (places.getStatus().isSuccess()) { final Place thatPlace = places.get(0); LatLng queriedLocation = thatPlace.getLatLng(); Log.v("Latitude is", "" + queriedLocation.latitude); Log.v("Longitude is", "" + queriedLocation.longitude); observer.onNext(thatPlace.freeze()); } places.release(); } }); } }.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); }
@Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { final String placeId=dataSnapshot.getKey(); if(placeId!=null) { Places.GeoDataApi .getPlaceById(mGoogleApiClient,placeId) .setResultCallback(new ResultCallback<PlaceBuffer>() { @Override public void onResult(@NonNull PlaceBuffer places) { LatLng location=places.get(0).getLatLng(); //CharSequence userName=places.get(1).getName(); //Toast.makeText(getApplicationContext(),"reached onChildAdded",Toast.LENGTH_SHORT).show(); addPointToView(location); mMap.addMarker(new MarkerOptions() .position(location)); //Toast.makeText(getApplicationContext(),"place added",Toast.LENGTH_SHORT).show(); places.release(); } }); } }
@Override public void onItemClick (AdapterView<?> parent, View view, int position, long id) { /* Retrieve the place ID of the selected item from the Adapter. The adapter stores each Place suggestion in a AutocompletePrediction from which we read the place ID and title. */ final AutocompletePrediction item = mAdapter.getItem (position); final String placeId = item.getPlaceId (); final CharSequence primaryText = item.getPrimaryText (null); Log.i("", "Autocomplete item selected: " + primaryText); /* Issue a request to the Places Geo Data API to retrieve a Place object with additional details about the place. */ PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi .getPlaceById (mGoogleApiClient, placeId); placeResult.setResultCallback (mUpdatePlaceDetailsCallback); Log.i("", "Called getPlaceById to get Place details for " + placeId); mSearchLocation.setThreshold(1000); }
@Override public void onResult (PlaceBuffer places) { if (!places.getStatus ().isSuccess ()) { // Request did not statusComplete successfully Log.e("", "Place query did not statusComplete. Error: " + places.getStatus().toString()); places.release (); return; } // Get the Place object from the buffer. final Place place = places.get (0); Log.e("Place", place.getAddress() + ""); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 16.0f)); Log.i("", "LatLog " + place.getLatLng()); Log.i("", "Place details received: " + place.getName()); places.release(); }
@Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { Log.e(LOG_TAG, "Place query did not complete. Error: " + places.getStatus().toString()); return; } // Selecting the first object buffer. final Place place = places.get(0); CharSequence attributions = places.getAttributions(); mNameTextView.setText(Html.fromHtml(place.getName() + "")); mAddressTextView.setText(Html.fromHtml(place.getAddress() + "")); mIdTextView.setText(Html.fromHtml(place.getId() + "")); mPhoneTextView.setText(Html.fromHtml(place.getPhoneNumber() + "")); mWebTextView.setText(place.getWebsiteUri() + ""); if (attributions != null) { mAttTextView.setText(Html.fromHtml(attributions.toString())); } }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { /* Retrieve the place ID of the selected item from the Adapter. The adapter stores each Place suggestion in a AutocompletePrediction from which we read the place ID and title. */ final AutocompletePrediction item = mAdapter.getItem(position); final String placeId = item.getPlaceId(); final CharSequence primaryText = item.getPrimaryText(null); Log.i(TAG, "Autocomplete item selected: " + primaryText); /* Issue a request to the Places Geo Data API to retrieve a Place object with additional details about the place. */ PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi .getPlaceById(mGoogleApiClient, placeId); placeResult.setResultCallback(mUpdatePlaceDetailsCallback); Toast.makeText(getApplicationContext(), "Clicked: " + primaryText, Toast.LENGTH_SHORT).show(); Log.i(TAG, "Called getPlaceById to get Place details for " + placeId); }
/** * Act upon new check-outs when they appear. */ @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { String placeId = dataSnapshot.getKey(); if (placeId != null) { Places.GeoDataApi .getPlaceById(mGoogleApiClient, placeId) .setResultCallback(new ResultCallback<PlaceBuffer>() { @Override public void onResult(PlaceBuffer places) { LatLng location = places.get(0).getLatLng(); addPointToViewPort(location); mMap.addMarker(new MarkerOptions().position(location)); places.release(); } } ); } }
private void findPlaceById( String id ) { if( TextUtils.isEmpty( id ) || mGoogleApiClient == null || !mGoogleApiClient.isConnected() ) return; Places.GeoDataApi.getPlaceById( mGoogleApiClient, id ) .setResultCallback( new ResultCallback<PlaceBuffer>() { @Override public void onResult(PlaceBuffer places) { if( places.getStatus().isSuccess() ) { Place place = places.get( 0 ); displayPlace( place ); mPredictTextView.setText( "" ); mAdapter.clear(); } //Release the PlaceBuffer to prevent a memory leak places.release(); } } ); }
/** * Returns observable that fetches a place from the Places API using the place ID. * * @param placeId id for place * @return observable that emits places buffer and completes */ public Observable<PlaceBuffer> getPlaceById(@Nullable final String placeId) { return getGoogleApiClientObservable(Places.PLACE_DETECTION_API, Places.GEO_DATA_API) .flatMap(new Func1<GoogleApiClient, Observable<PlaceBuffer>>() { @Override public Observable<PlaceBuffer> call(GoogleApiClient api) { return fromPendingResult(Places.GeoDataApi.getPlaceById(api, placeId)); } }); }
public void swapPlaces(PlaceBuffer newPlaces){ mPlaces = newPlaces; if (mPlaces!= null) //force the recyclerview to reload. this.notifyDataSetChanged(); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { AnalyticsManager.getInstance().trackSearch(); final AutocompletePrediction item = mAdapter.getItem(position); final String placeId = item.getPlaceId(); final CharSequence primaryText = item.getPrimaryText(null); PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi .getPlaceById(mGoogleApiClient, placeId); placeResult.setResultCallback(mUpdatePlaceDetailsCallback); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { UIUtils.hideKeyboard(AutoCompleteLocation.this.getContext(), AutoCompleteLocation.this); final AutocompletePrediction item = mAutoCompleteAdapter.getItem(position); if (item != null) { final String placeId = item.getPlaceId(); PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId); placeResult.setResultCallback(mUpdatePlaceDetailsCallback); } }
@Override public void onResult(@NonNull PlaceBuffer places) { if (!places.getStatus().isSuccess()) { places.release(); return; } final Place place = places.get(0); if (mAutoCompleteLocationListener != null) { mAutoCompleteLocationListener.onItemSelected(place); } places.release(); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final AutocompletePrediction item = mAdapter.getItem(position); final String placeId = item.getPlaceId(); PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi .getPlaceById(mGoogleApiClient, placeId); placeResult.setResultCallback(mUpdatePlaceDetailsCallback); }
@Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { if (callback != null) callback.onSuggestFail(places.getStatus()); places.release(); return; } final Place place = places.get(0); if (callback != null) callback.onSuggestResult(place, myact); places.release(); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final PlaceAdapter.PlaceAutocomplete item = mPlaceArrayAdapter.getItem(position); final String placeId = String.valueOf(item.placeId); PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId); placeResult.setResultCallback(mUpdatePlaceDetailsCallback); }
@Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { return; } place = places.get(0); }
@Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { return; } // Selecting the first object buffer. place = places.get(0); addLocation.setText(place.getAddress().toString()); return; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { InputMethodManager in = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); in.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0); final PlaceArrayAdapter.PlaceAutocomplete item = mPlaceArrayAdapter.getItem(position); final String placeId = String.valueOf(item.placeId); final_placeId = placeId; Log.i(LOG_TAG, final_placeId); PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi .getPlaceById(mGoogleApiClient, placeId); placeResult.setResultCallback(mUpdatePlaceDetailsCallback); }
@Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { Log.e(LOG_TAG, "Place query did not complete. Error: " + places.getStatus().toString()); return; } // Selecting the first object buffer. final Place place = places.get(0); CharSequence attributions = places.getAttributions(); }
private void loadPlaceInfo(Address address) { Places.GeoDataApi.getPlaceById(mGoogleApiClient, address.getPlaceId()) .setResultCallback(new ResultCallback<PlaceBuffer>() { @Override public void onResult(@NonNull PlaceBuffer places) { if (places.getStatus().isSuccess() && places.getCount() > 0) { Place place = places.get(0); LatLng latLng = place.getLatLng(); Subscription subscription = getWeatherForecast(latLng.latitude, latLng.longitude) .subscribe(new Subscriber<WeatherData>() { @Override public void onCompleted() { Timber.d("onCompleted()"); } @Override public void onError(Throwable e) { handleError(e); } @Override public void onNext(WeatherData weatherData) { updateUi(weatherData); } }); mCompositeSubscription.add(subscription); } else { Timber.e("Place not found"); } places.release(); } }); }
@Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { places.release(); return; } // Get the Place object from the buffer. final Place place = places.get(0); hideKeyboard(); mLatitude=String.valueOf(place.getLatLng().latitude); mLongitude=String.valueOf(place.getLatLng().longitude); LatLng newLatLngTemp = new LatLng(place.getLatLng().latitude, place.getLatLng().longitude); // LatLng centerLatLng=new LatLng(mMap.getCameraPosition().target.latitude,mMap.getCameraPosition().target.longitude); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(newLatLngTemp, 15f)); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final PlaceAutocompleteAdapter.PlaceAutocomplete item = mAdapter.getItem(position); final String placeId = String.valueOf(item.placeId); PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi .getPlaceById(mGoogleApiClient, placeId); placeResult.setResultCallback(mUpdatePlaceDetailsCallback); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final PlaceArrayAdapter.PlaceAutocomplete item = mPlaceArrayAdapter.getItem(position); final String placeId = String.valueOf(item.placeId); Log.i(LOG_TAG, "Selected: " + item.description); PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi .getPlaceById(mGoogleApiClient, placeId); placeResult.setResultCallback(mUpdatePlaceDetailsCallback); Log.i(LOG_TAG, "Fetching details for ID: " + item.placeId); }
public void findStationByID(String placeId, final StationFoundListener stationFoundListener){ Places.GeoDataApi.getPlaceById(googleApiClient, placeId) .setResultCallback(new ResultCallback<PlaceBuffer>() { @Override public void onResult(PlaceBuffer places) { if (places.getStatus().isSuccess() && places.getCount() > 0) { Station station = new Station(places.get(0)); stationFoundListener.OnFindStationResult(station); } else { stationFoundListener.OnFindStationResult(null); } places.release(); } }); }
@Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { // Request did not complete successfully Log.e(TAG, "Place query did not complete. Error: " + places.getStatus().toString()); places.release(); return; } // Get the Place object from the buffer. final Place place = places.get(0); // Format details of the place for display and show it in a TextView. mPlaceDetailsText.setText(formatPlaceDetails(getResources(), place.getName(), place.getId(), place.getAddress(), place.getPhoneNumber(), place.getWebsiteUri())); // Display the third party attributions if set. final CharSequence thirdPartyAttribution = places.getAttributions(); if (thirdPartyAttribution == null) { mPlaceDetailsAttribution.setVisibility(View.GONE); } else { mPlaceDetailsAttribution.setVisibility(View.VISIBLE); mPlaceDetailsAttribution.setText(Html.fromHtml(thirdPartyAttribution.toString())); } Log.i(TAG, "Place details received: " + place.getName()); places.release(); }
/** * Constructor to initialise the adapter using context and the db cursor. * @param mContext {@link Context} Passing in the context from the activity. * @param mPlaces {@link PlaceBuffer} A buffer for storing a list of places selected by the user. */ public PlaceListAdapter(Context mContext,PlaceBuffer mPlaces) { this.mContext = mContext; this.mPlaces = mPlaces; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { /* Retrieve the place ID of the selected item from the Adapter. The adapter stores each Place suggestion in a PlaceAutocomplete object from which we read the place ID. */ final PlaceAutocompleteAdapter.PlaceAutocomplete item = adapter.getItem(position); final String placeId = String.valueOf(item.placeId); /* Issue a request to the Places Geo Data API to retrieve a Place object with additional details about the place. */ progressBar.setVisibility(View.VISIBLE); PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi.getPlaceById(googleApiClient, placeId); placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() { @Override public void onResult(PlaceBuffer places) { if (!places.getStatus().isSuccess()) { // Request did not complete successfully places.release(); return; } Place place; try { place = places.get(0); } catch (IllegalStateException e) { places.release(); return; } lastSelected = new org.croudtrip.db.Place(); lastSelected.setId(place.getId()); lastSelected.setDescription(place.getAddress() + ""); tv_address.setText(place.getAddress()); progressBar.setVisibility(View.GONE); places.release(); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } }); Toast.makeText(getActivity().getApplicationContext(), "Clicked: " + item.description, Toast.LENGTH_SHORT).show(); }
public PlaceAutoCompleteOnItemClickListener(GoogleApiClient googleApiClient, PlaceAutoCompleteAdapter adapter, ResultCallback<PlaceBuffer> resultCallback) { this.googleApiClient = googleApiClient; this.placeAutoCompleteAdapter = adapter; this.resultCallback = resultCallback; }