2010-05-06 6 views
6

यह वह जगह है में एक मूल रूप से आवेदन जहां मैं इस प्रारूप 28 "41'44.13597 में एक तस्वीर के मेटा डेटा से अक्षांश जानकारी हो रही है जीपीएस।कैसे दशमलव में दूसरी डिग्री मिनट कन्वर्ट करने के लिए जावा

मेरे जरूरत है पहले से दशमलव में एक ही जानकारी को परिवर्तित करने और बाहर 28.705450 तरह दशमलव प्रारूप में डेटा प्रदर्शित करेगी।

कृपया कोड या किसी संदर्भ के माध्यम से मदद

धन्यवाद

उत्तर

6
/** answer=hour+minutes/60+seconds/3600 */ 
public double convertHourToDecimal(String degree) { 
    if(!degree.matches("(-)?[0-6][0-9]\"[0-6][0-9]\'[0-6][0-9](.[0-9]{1,5})?") 
     throw new IllegalArgumentException(); 
    String[] strArray=degree.split("[\"']"); 
    return Double.parseDouble(strArray[0])+Double.parseDouble(strArray[1])/60+Double.parseDouble(strArray[2])/3600; 
} 
+0

यदि आप यह सुनिश्चित करना चाहते हैं कि डेटा सही रूप से स्वरूपित है, तो प्रोग्राम को "डिग्री का पालन करें और मिनटों का पालन करने के लिए सुनिश्चित करना चाहिए? – LandonSchropp

+0

@helixed, जोड़ा गया प्रारूप जांच कोड – TiansHUo

+0

प्रारूप जांच कोड काम नहीं करता है (68 "62'65.9 पास, लेकिन -82" 30'0 विफल हो जाता है) –

6

60. और 3600. द्वारा सेकंड को विभाजित करें, फिर तीनों को एक साथ जोड़ें।

5

मुझे लगता है कि आप लेकिन सूत्र लिए यह कर देगा डिग्री से डिग्री दशमलव में बदलने के लिए किसी भी जावा पुस्तकालय की नहीं जानता है: डिग्री + (मिनट/60) + (सेकंड/(60 * 60))

-1
package newstract; 

import java.io.File; 
import java.util.Date; 
import com.drew.imaging.jpeg.JpegMetadataReader; 
import com.drew.metadata.Directory; 
import com.drew.metadata.Metadata; 
import com.drew.metadata.exif.ExifDirectory; 
import java.text.SimpleDateFormat; 
import com.drew.metadata.exif.GpsDirectory; 

public class GetTagInfo { 
    public static void main(String[] args) 
    { 
     System.out.println("Picture Tagged Details"); 
     try{ 
     File jpegFile = new File("DSC_0060.JPG"); 
     Metadata metadata = JpegMetadataReader.readMetadata(jpegFile); 
     Directory exifDirectory = metadata.getDirectory(ExifDirectory.class); 
     SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss"); 
     Date myDate = exifDirectory.getDate(ExifDirectory.TAG_DATETIME); 
     System.out.println(sdf.format(myDate)); 
     SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy"); 
     Date myDate1 = exifDirectory.getDate(ExifDirectory.TAG_DATETIME); 
     System.out.println(sdf1.format(myDate1)); 
     SimpleDateFormat sdf2 = new SimpleDateFormat("hh:mm:ss"); 
     Date myDate3 = exifDirectory.getDate(ExifDirectory.TAG_DATETIME); 
     System.out.println(sdf2.format(myDate3)); 


     Directory gpsDirectory = metadata.getDirectory(GpsDirectory.class); 
     // Boolean b = (gpsDirectory.containsTag(GpsDirectory.TAG_GPS_LATITUDE)); 
     // System.out.println(GpsDirectory.TAG_GPS_LATITUDE);+ 
     String s = gpsDirectory.getDescription(2); 
     System.out.println(s); 
     SplitString1 w = new SplitString1(); 
     w.doit(s); 



     Iterator directories = metadata.getDirectoryIterator(); 
     while (directories.hasNext()) { 
     GpsDescriptor directory = (GpsDescriptor) directories.next(); 
     System.out.print(directory.getGpsLatitudeDescription()); 
     } 

     } // close of catch 
     catch (Exception e) { 
      System.err.println(e.getMessage()); 
      //System.err.println(tag.getDirectoryName() + " " + tag.getTagName() + " (error)"); 
     } 

} 

} 

class SplitString1 { 

    public void doit(String lat) { 

     String str = lat; 
     String [] temp = null; 
     String dtemp = null; 
     //temp = str.split("[\"]|\"[\']"); 
     temp = str.split("[\"]|[\']"); 
     dtemp = str.replace("\"", "°"); 
     System.out.println("Formated DCM : "+dtemp); 
     dump(temp); 


    } 

    public void dump(String []s) { 
     for (int i = 0 ; i < s.length ; i++) { 
      System.out.println("\ndegree : "+s[0]); 
      System.out.println("\nminutes : "+s[1]); 
      System.out.println("\nsecond : "+s[2]); 

      String deg = s[0] ; 
      int ndeg = Integer.parseInt(deg); 
      String min = s[1] ; 
      double nmin = Double.parseDouble(min); 
      String sec = s[2] ; 
      double nsec = Double.parseDouble(sec); 
      double decimaldms = (ndeg+(nmin/60)+(nsec/3600)); 
      System.out.println("\nfinaldecimal : "+decimaldms); 
     } 
    } 

    // Decimal degrees = whole number of degrees, plus minutes divided by 60, 
    //plus seconds divided by 3600 
} 
संबंधित मुद्दे

 संबंधित मुद्दे