Guest User

Untitled

a guest
Oct 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. locationClient = LocationServices.getFusedLocationProviderClient(this);
  2. googleApiClient = new GoogleApiClient.Builder(this)
  3. .addApi(LocationServices.API)
  4. .addConnectionCallbacks(this)
  5. .build();
  6.  
  7. @Override
  8. public void onConnected(@Nullable Bundle bundle) {
  9. updateLocation();
  10. }
  11.  
  12. @Override
  13. public void onConnectionSuspended(int i) {
  14. googleApiClient.connect();
  15. }
  16.  
  17. @SuppressWarnings({"MissingPermission"})
  18. @OnClick(R.id.searchRestaurantsFab)
  19. public void updateLocation() {
  20. locationClient.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {
  21. @Override
  22. public void onSuccess(Location location) {
  23. if (location == null) {
  24. Toast.makeText(MapsActivity.this, "Включите GPS", Toast.LENGTH_SHORT).show();
  25. } else if (mapIsReady) {
  26. mapsFragment.showMyLocation(location);
  27. updateRestaurants(location);
  28. }
  29. }
  30. });
  31. }
Add Comment
Please, Sign In to add comment