GeoCoordinate - 如何将其格式化为纬度、经度?
GeoCoordinate - How do I format it into for latitude, longitude?
我正在使用 PositioningManager
class 获取我当前的地理坐标
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();
}
准确性不是位置。使用getCoordinate().getLongitude()
等。
不要使用 Android 的 android.location.Location 来处理 HERE SDK GeoPosition
class.
特别是line 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()));
尝试使用 LocationMethod.GPS_NETWORK
而不是 LocationMethod.GPS
。
然后使用getCoordinate().getLongitude()
.
我正在使用 PositioningManager
class 获取我当前的地理坐标
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();
}
准确性不是位置。使用getCoordinate().getLongitude()
等。
不要使用 Android 的 android.location.Location 来处理 HERE SDK GeoPosition
class.
特别是line 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()));
尝试使用 LocationMethod.GPS_NETWORK
而不是 LocationMethod.GPS
。
然后使用getCoordinate().getLongitude()
.