com.drew.lang.GeoLocation Java Examples

The following examples show how to use com.drew.lang.GeoLocation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GpsDirectory.java    From metadata-extractor with Apache License 2.0 6 votes vote down vote up
/**
 * Parses various tags in an attempt to obtain a single object representing the latitude and longitude
 * at which this image was captured.
 *
 * @return The geographical location of this image, if possible, otherwise null
 */
@Nullable
public GeoLocation getGeoLocation()
{
    Rational[] latitudes = getRationalArray(TAG_LATITUDE);
    Rational[] longitudes = getRationalArray(TAG_LONGITUDE);
    String latitudeRef = getString(TAG_LATITUDE_REF);
    String longitudeRef = getString(TAG_LONGITUDE_REF);

    // Make sure we have the required values
    if (latitudes == null || latitudes.length != 3)
        return null;
    if (longitudes == null || longitudes.length != 3)
        return null;
    if (latitudeRef == null || longitudeRef == null)
        return null;

    Double lat = GeoLocation.degreesMinutesSecondsToDecimal(latitudes[0], latitudes[1], latitudes[2], latitudeRef.equalsIgnoreCase("S"));
    Double lon = GeoLocation.degreesMinutesSecondsToDecimal(longitudes[0], longitudes[1], longitudes[2], longitudeRef.equalsIgnoreCase("W"));

    // This can return null, in cases where the conversion was not possible
    if (lat == null || lon == null)
        return null;

    return new GeoLocation(lat, lon);
}
 
Example #2
Source File: MetadataHelper.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
public MediaDetailsMap<String, String> getMainDetails(Context context, Media m) {
    MediaDetailsMap<String, String> details = new MediaDetailsMap<>();
    details.put(context.getString(R.string.path), m.getDisplayPath());
    details.put(context.getString(R.string.type), m.getMimeType());
    if (m.getSize() != -1)
        details.put(context.getString(R.string.size), StringUtils.humanReadableByteCount(m.getSize(), true));
    // TODO should i add this always?
    details.put(context.getString(R.string.orientation), m.getOrientation() + "");
    MetaDataItem metadata = MetaDataItem.getMetadata(context, m.getUri());
    details.put(context.getString(R.string.resolution), metadata.getResolution());
    details.put(context.getString(R.string.date), SimpleDateFormat.getDateTimeInstance().format(new Date(m.getDateModified())));
    Date dateOriginal = metadata.getDateOriginal();
    if (dateOriginal != null)
        details.put(context.getString(R.string.date_taken), SimpleDateFormat.getDateTimeInstance().format(dateOriginal));

    String tmp;
    if ((tmp = metadata.getCameraInfo()) != null)
        details.put(context.getString(R.string.camera), tmp);
    if ((tmp = metadata.getExifInfo()) != null)
        details.put(context.getString(R.string.exif), tmp);
    GeoLocation location;
    if ((location = metadata.getLocation()) != null)
        details.put(context.getString(R.string.location), location.toDMSString());


    return details;
}
 
Example #3
Source File: GpsDescriptor.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Nullable
private String getGeoLocationDimension(int tagValue, int tagRef, String positiveRef)
{
    Rational[] values = _directory.getRationalArray(tagValue);
    String ref = _directory.getString(tagRef);

    if (values == null || values.length != 3 || ref == null)
        return null;

    Double dec = GeoLocation.degreesMinutesSecondsToDecimal(
        values[0], values[1], values[2], ref.equalsIgnoreCase(positiveRef));

    return dec == null ? null : GeoLocation.decimalToDegreesMinutesSecondsString(dec);
}
 
Example #4
Source File: ExifDirectoryTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testGeoLocation() throws IOException, MetadataException
{
    Metadata metadata = ExifReaderTest.processBytes("Tests/Data/withExifAndIptc.jpg.app1.0");

    GpsDirectory gpsDirectory = metadata.getFirstDirectoryOfType(GpsDirectory.class);
    assertNotNull(gpsDirectory);
    GeoLocation geoLocation = gpsDirectory.getGeoLocation();
    assertEquals(54.989666666666665, geoLocation.getLatitude(), 0.001);
    assertEquals(-1.9141666666666666, geoLocation.getLongitude(), 0.001);
}
 
Example #5
Source File: MetaDataItem.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
public GeoLocation getLocation() {
    return location;
}
 
Example #6
Source File: Media.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public GeoLocation getGeoLocation() {
    return /*metadata != null ? metadata.getLocation() :*/ null;
}
 
Example #7
Source File: AlertDialogsHelper.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
public static AlertDialog getDetailsDialog(final ThemedActivity activity, final Media f) {
    AlertDialog.Builder detailsDialogBuilder = new AlertDialog.Builder(activity, activity.getDialogStyle());
    MetadataHelper mdhelper = new MetadataHelper();
    MediaDetailsMap<String, String> mainDetails = mdhelper.getMainDetails(activity, f);
    final View dialogLayout = activity.getLayoutInflater().inflate(com.alienpants.leafpicrevived.R.layout.dialog_media_detail, null);
    ImageView imgMap = dialogLayout.findViewById(R.id.photo_map);
    dialogLayout.findViewById(com.alienpants.leafpicrevived.R.id.details_title).setBackgroundColor(activity.getPrimaryColor());
    ((CardView) dialogLayout.findViewById(com.alienpants.leafpicrevived.R.id.photo_details_card)).setCardBackgroundColor(activity.getCardBackgroundColor());

    final GeoLocation location;
    if ((location = f.getGeoLocation()) != null) {

        StaticMapProvider staticMapProvider = StaticMapProvider.fromValue(
                Hawk.get(activity.getString(R.string.preference_map_provider), StaticMapProvider.GOOGLE_MAPS.getValue()));

        Glide.with(activity.getApplicationContext())
                .load(staticMapProvider.getUrl(location))
                .into(imgMap);

        imgMap.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                try {
                    activity.startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse(String.format(Locale.ENGLISH, "geo:%f,%f?z=%d", location.getLatitude(), location.getLongitude(), 17))));
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(activity, R.string.no_app_to_perform, Toast.LENGTH_SHORT).show();
                }

            }
        });

        imgMap.setVisibility(View.VISIBLE);
        dialogLayout.findViewById(com.alienpants.leafpicrevived.R.id.details_title).setVisibility(View.GONE);

    } else imgMap.setVisibility(View.GONE);

    final TextView showMoreText = dialogLayout.findViewById(R.id.details_showmore);
    showMoreText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showMoreDetails(dialogLayout, activity, f);
            showMoreText.setVisibility(View.GONE);
        }
    });

    detailsDialogBuilder.setView(dialogLayout);
    loadDetails(dialogLayout, activity, mainDetails);
    return detailsDialogBuilder.create();
}
 
Example #8
Source File: Location.java    From cineast with MIT License 4 votes vote down vote up
public static Location of(GeoLocation geoLocation) {
  return of((float) geoLocation.getLatitude(), (float) geoLocation.getLongitude());
}
 
Example #9
Source File: GpsDescriptor.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Nullable
public String getGpsLatitudeDescription()
{
    GeoLocation location = _directory.getGeoLocation();
    return location == null ? null : GeoLocation.decimalToDegreesMinutesSecondsString(location.getLatitude());
}
 
Example #10
Source File: GpsDescriptor.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Nullable
public String getGpsLongitudeDescription()
{
    GeoLocation location = _directory.getGeoLocation();
    return location == null ? null : GeoLocation.decimalToDegreesMinutesSecondsString(location.getLongitude());
}
 
Example #11
Source File: GpsDescriptor.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Nullable
public String getDegreesMinutesSecondsDescription()
{
    GeoLocation location = _directory.getGeoLocation();
    return location == null ? null : location.toDMSString();
}
 
Example #12
Source File: GeoTagMapBuilder.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
public PhotoLocation(final GeoLocation location, final File file)
{
    this.location = location;
    this.file = file;
}