Guest User

google api

a guest
Apr 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. //this is my location
  2. new LatLngBounds(
  3.                 new LatLng(39.612137,-8.960664),
  4.  
  5.                 new LatLng(39.815083,-8.704472));
  6.  
  7. ///////////////////
  8.  
  9. public void setBounds(LatLngBounds bounds) {
  10.         final double HEADING_NORTH_EAST = 45;
  11.         final double HEADING_SOUTH_WEST = 215;
  12.         final double diagonalBoundsSize = 1000; // 1km
  13.  
  14.         LatLng centre = bounds.getCenter();
  15.  
  16.         LatLng northEast = SphericalUtil.computeOffset(centre, diagonalBoundsSize / 2, HEADING_NORTH_EAST);
  17.         LatLng southWest = SphericalUtil.computeOffset(centre, diagonalBoundsSize / 2, HEADING_SOUTH_WEST);
  18.         this.bounds = new LatLngBounds(southWest, northEast);
  19.         //this.bounds = bounds;
  20.     }
  21.  
  22.  
  23. public void search(String searchText){
  24. PendingResult<AutocompletePredictionBuffer> results =
  25.                     Places.GeoDataApi
  26.                             .getAutocompletePredictions(googleApiClient, searchText,
  27.                                     bounds, placeFilter);
  28.             // This method should have been called off the main UI thread. Block and wait for at most 60s
  29.             // for a result from the API.
  30.             AutocompletePredictionBuffer autocompletePredictions = results
  31.                     .await(60, TimeUnit.SECONDS);
  32.  
  33.             // Confirm that the query completed successfully, otherwise return null
  34.             final Status status = autocompletePredictions.getStatus();
  35.  
  36.             if (!status.isSuccess()) {
  37.                 Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
  38.                         Toast.LENGTH_SHORT).show();
  39.             }else{
  40.                 for (AutocompletePrediction au:autocompletePredictions) {
  41.                     String data = au.getFullText(STYLE_BOLD).toString();
  42.                     Log.e(TAG, "getAuto: "+data);
  43.                         SearchItem item = new SearchItem(au.getPlaceId(), au.getPrimaryText(STYLE_BOLD).toString(), R.drawable.ic_pin, TypeItemMarker.PLACE);
  44.                         item.setmSecondName(au.getSecondaryText(STYLE_BOLD).toString());
  45.                         searchList.add(item);
  46.                 }
  47.             }
  48.  
  49. }
Add Comment
Please, Sign In to add comment