Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this is my location
- new LatLngBounds(
- new LatLng(39.612137,-8.960664),
- new LatLng(39.815083,-8.704472));
- ///////////////////
- public void setBounds(LatLngBounds bounds) {
- final double HEADING_NORTH_EAST = 45;
- final double HEADING_SOUTH_WEST = 215;
- final double diagonalBoundsSize = 1000; // 1km
- LatLng centre = bounds.getCenter();
- LatLng northEast = SphericalUtil.computeOffset(centre, diagonalBoundsSize / 2, HEADING_NORTH_EAST);
- LatLng southWest = SphericalUtil.computeOffset(centre, diagonalBoundsSize / 2, HEADING_SOUTH_WEST);
- this.bounds = new LatLngBounds(southWest, northEast);
- //this.bounds = bounds;
- }
- public void search(String searchText){
- PendingResult<AutocompletePredictionBuffer> results =
- Places.GeoDataApi
- .getAutocompletePredictions(googleApiClient, searchText,
- bounds, placeFilter);
- // This method should have been called off the main UI thread. Block and wait for at most 60s
- // for a result from the API.
- AutocompletePredictionBuffer autocompletePredictions = results
- .await(60, TimeUnit.SECONDS);
- // Confirm that the query completed successfully, otherwise return null
- final Status status = autocompletePredictions.getStatus();
- if (!status.isSuccess()) {
- Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
- Toast.LENGTH_SHORT).show();
- }else{
- for (AutocompletePrediction au:autocompletePredictions) {
- String data = au.getFullText(STYLE_BOLD).toString();
- Log.e(TAG, "getAuto: "+data);
- SearchItem item = new SearchItem(au.getPlaceId(), au.getPrimaryText(STYLE_BOLD).toString(), R.drawable.ic_pin, TypeItemMarker.PLACE);
- item.setmSecondName(au.getSecondaryText(STYLE_BOLD).toString());
- searchList.add(item);
- }
- }
- }
Add Comment
Please, Sign In to add comment