Guest User

Position

a guest
Apr 19th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. public class Position {
  2.  
  3.     private static final String TAG = "Position";
  4.  
  5.     private Context context;
  6.     private Location loc;
  7.     public String latitude;
  8.     public String longitude;
  9.  
  10.     public Position(Context c) {
  11.         context=c;
  12.         setLocation();
  13.  
  14.     }
  15.  
  16.     private void setLocation() {
  17.         FusedLocationProviderClient fusedLocationClient;
  18.         fusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
  19.         fusedLocationClient.getLastLocation().addOnSuccessListener((Activity) context,  new OnSuccessListener<Location>() {
  20.             @Override
  21.             public void onSuccess(Location location) {
  22.                 if (location != null) {
  23.                     setLatitude(location);
  24.                     setLongitiude(location);
  25.                     Log.d(TAG, "Location is set!");
  26.                 } else {
  27.                     loc = null;
  28.                     Log.d(TAG, "Location is not set!");
  29.                 }
  30.             }
  31.         });
  32.     }
  33.  
  34.     private void setLatitude(Location location) {
  35.         this.latitude = String.valueOf(location.getLatitude());
  36.         Log.d(TAG, latitude);   //pokazuje poprawne współrzędne
  37.     }
  38.  
  39.     public String getLatitude() {
  40.         return this.latitude;
  41.     }
  42.  
  43.     private void setLongitiude(Location location) {
  44.         this.longitude = String.valueOf(location.getLongitude());
  45.         Log.d(TAG, longitude);  // //pokazuje poprawne współrzędne
  46.     }
  47.  
  48.     public String getLongitude() {
  49.         return this.longitude;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment