Thursday, 10 December 2020

GeoCoordinate - How do I format it into for latitude, longitude?

I'm using the PositioningManager class to get my current geocoordinates

PositioningManager posManager = PositioningManager.getInstance();
posManager.start(PositioningManager.LocationMethod.GPS);
GeoPosition position = posManager.getPosition();
Log.d(TAG, "onMyLocationClick: " + position.getLatitudeAccuracy() + ", " + position.getLongitudeAccuracy());

however it's returning me

1.07374182E9, 1.07374182E9

for lat lng

how do I format it so that it's like:

40.712776, -74.005974

Check permissions code:

public void checkLocationPermission(){
        Dexter.withActivity(this)
                .withPermission(Manifest.permission.ACCESS_FINE_LOCATION)
                .withListener(new PermissionListener() {
                    @Override public void onPermissionGranted(PermissionGrantedResponse response) {
                        PositioningManager posManager = PositioningManager.getInstance();
                        posManager.start(PositioningManager.LocationMethod.GPS);
                        GeoPosition position = posManager.getPosition();

                        Log.d(TAG, "onPermissionGranted: " + position.isValid());

                        try {
                            String strLatitude = Location.convert(position.getCoordinate().getLatitude(), Location.FORMAT_DEGREES);
                            String strLongitude = Location.convert(position.getCoordinate().getLongitude(), Location.FORMAT_DEGREES);
                            Log.d(TAG, "onMyLocationClick: " + strLatitude + ", " + strLongitude);
                        }catch (Exception e){
                            Log.e(TAG, "onPermissionGranted: Error: " + e);
                        }

                    }
                    @Override public void onPermissionDenied(PermissionDeniedResponse response) {
                        Log.d(TAG, "onPermissionDenied: Permission denied");
                    }
                    @Override public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
                        Log.d(TAG, "onPermissionRationaleShouldBeShown: Called");
                        token.continuePermissionRequest();
                    }
                }).check();
    }


from GeoCoordinate - How do I format it into for latitude, longitude?

No comments:

Post a Comment