Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Position {
- private static final String TAG = "Position";
- private Context context;
- private Location loc;
- public String latitude;
- public String longitude;
- public Position(Context c) {
- context=c;
- setLocation();
- }
- private void setLocation() {
- FusedLocationProviderClient fusedLocationClient;
- fusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
- fusedLocationClient.getLastLocation().addOnSuccessListener((Activity) context, new OnSuccessListener<Location>() {
- @Override
- public void onSuccess(Location location) {
- if (location != null) {
- setLatitude(location);
- setLongitiude(location);
- Log.d(TAG, "Location is set!");
- } else {
- loc = null;
- Log.d(TAG, "Location is not set!");
- }
- }
- });
- }
- private void setLatitude(Location location) {
- this.latitude = String.valueOf(location.getLatitude());
- Log.d(TAG, latitude); //pokazuje poprawne współrzędne
- }
- public String getLatitude() {
- return this.latitude;
- }
- private void setLongitiude(Location location) {
- this.longitude = String.valueOf(location.getLongitude());
- Log.d(TAG, longitude); // //pokazuje poprawne współrzędne
- }
- public String getLongitude() {
- return this.longitude;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment