1

我正在使用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();
    }
4

3 回答 3

1

不要使用 Android 的android.location.Location来处理 HERE SDKGeoPosition类。

只需按照HERE SDK 示例应用

特别是第 344 行

GeoPosition geoPosition
...
final GeoCoordinate coord = geoPosition.getCoordinate();
sb.append("Type: ").append(String.format(Locale.US, "%s\n", locationMethod.name()));
sb.append("Coordinate:").append(String.format(Locale.US, "%.6f, %.6f\n", coord.getLatitude(), coord.getLongitude()));
于 2020-12-15T16:22:23.763 回答
0

准确性不是立场。使用getCoordinate().getLongitude()等。

于 2020-12-07T05:58:38.830 回答
0

尝试使用LocationMethod.GPS_NETWORK而不是LocationMethod.GPS.

然后使用getCoordinate().getLongitude().

于 2020-12-15T16:44:52.287 回答