gpt4 book ai didi

java - 如何从 GpsDirectory 获取经纬度的实际值?

转载 作者:搜寻专家 更新时间:2023-11-01 03:08:11 26 4
gpt4 key购买 nike

我正在编写一个 Java 程序,它实际上读取图像的所有元数据(例如纬度、经度和日期时间)。以下是我正在运行的示例代码。

public static void findLatLong(File jpg){
try {
Metadata metadata = ImageMetadataReader.readMetadata(jpg);
if (metadata.containsDirectory(GpsDirectory.class)) {
GpsDirectory gpsDir =(GpsDirectory)metadata.getDirectory(GpsDirectory.class);
GpsDescriptor gpsDesc = new GpsDescriptor(gpsDir);
System.out.println("Latitude: " + gpsDesc.getGpsLatitudeDescription());
System.out.println("Longitude : " + gpsDesc.getGpsLongitudeDescription());
System.out.println("Date : " + gpsDesc.getGpsTimeStampDescription());
System.out.println("Minute : " + gpsDesc.getDegreesMinutesSecondsDescription());
}else{
// System.out.println("----- Did not find GPS Information-------------for file " + jpg.getName() );
}

} catch (ImageProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

输出:-纬度:21.0° 8.0' 22.999999999998693"经度 : 79.0° 3.0' 12.999999999994998"日期 : 14:16:30 UTC分:21.0° 8.0' 22.999999999998693", 79.0° 3.0' 12.999999999994998"

我想这都是学位格式。谁能指出我如何获得经纬度的真正值(value)。并获得适当的日期。

最佳答案

如果使用元数据提取器 >= 2.6.0,您可以使用新的 com.drew.lang.GeoLocation类(changelog)。

GpsDirectory gpsDirectory = metadata.getDirectory(GpsDirectory.class);
GeoLocation location = gpsDirectory.getGeoLocation();
double lat = location.getLatitude();
double lng = location.getLongitude();

如果没有,这就是在 new class sources 中所做的:

   /**
* Converts DMS (degrees-minutes-seconds) rational values, as given
* in {@link com.drew.metadata.exif.GpsDirectory},
* into a single value in degrees, as a double.
*/
@Nullable
public static Double degreesMinutesSecondsToDecimal(
@NotNull final Rational degs, @NotNull final Rational mins,
@NotNull final Rational secs, final boolean isNegative) {

double decimal = Math.abs(degs.doubleValue())
+ mins.doubleValue() / 60.0d
+ secs.doubleValue() / 3600.0d;

if (Double.isNaN(decimal))
return null;

if (isNegative)
decimal *= -1;

return decimal;
}

方法参数的来源:

Rational[] latitudes = getRationalArray(GpsDirectory.TAG_LATITUDE);
Rational[] longitudes = getRationalArray(GpsDirectory.TAG_LONGITUDE);
String latitudeRef = getString(GpsDirectory.TAG_LATITUDE_REF);
String longitudeRef = getString(GpsDirectory.TAG_LONGITUDE_REF);

关于java - 如何从 GpsDirectory 获取经纬度的实际值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15352446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com