我正在使用PositioningManager
该类来获取我当前的地理坐标
PositioningManager posManager = PositioningManager.getInstance();
posManager.start(PositioningManager.LocationMethod.GPS);
GeoPosition position = posManager.getPosition();
Log.d(TAG, "onMyLocationClick: " + position.getLatitudeAccuracy() + ", " + position.getLongitudeAccuracy());
然而它让我回来了
1.07374182E9, 1.07374182E9
经纬度
我如何格式化它,使它像:
40.712776, -74.005974
检查权限代码:
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();
}