Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. package com.google.maps;
  2. import java.io.*;
  3. import java.net.*;
  4. import java.util.*;
  5. import java.sql.*;
  6.  
  7.  
  8. import java.sql.Statement;
  9. import java.sql.Connection;
  10. import java.sql.ResultSet;
  11. import java.sql.DriverManager;
  12. import java.sql.SQLException;
  13. import java.text.SimpleDateFormat;
  14.  
  15. import com.google.maps.internal.ApiConfig;
  16. import com.google.maps.internal.ApiResponse;
  17. import com.google.maps.model.GeocodingResult;
  18. import com.google.maps.model.LatLng;
  19.  
  20. public class FileHandler
  21. {
  22. public static void main(String [] args) {
  23.  
  24.  
  25. String fileName = "ascii_file";
  26.  
  27.  
  28. String line = null;
  29.  
  30. try {
  31.  
  32. FileReader fileReader =
  33. new FileReader(fileName);
  34.  
  35.  
  36. BufferedReader bufferedReader =
  37. new BufferedReader(fileReader);
  38.  
  39. while((line = bufferedReader.readLine()) != null) {
  40. System.out.println(line);
  41. int se = line.endsWith("<")? (line.length() - 1) : line.length();
  42.  
  43. System.out.println("se-----------------------------"+se);
  44. String parsedstring = line.substring(1,se);
  45. System.out.println("parsedString"+parsedstring);
  46. String T[] = parsedstring.split(";");
  47. System.out.println("ttttt-----------------------------"+T[0]);
  48.  
  49. String mobileID = null;
  50. for (int i = 1; i < T.length; i++) {
  51. if (T[i].startsWith("ID=")) {
  52. mobileID = T[i].substring(3);
  53.  
  54. System.out.println("mobileID-----------------"+mobileID);
  55. break;
  56.  
  57. }}
  58. int gpsTOD = Integer.parseInt(T[0].substring( 3, 8));
  59. float latitude = Float.parseFloat(T[0].substring( 8,16));
  60. float lat =latitude/100000;
  61.  
  62. float longitude = Float.parseFloat(T[0].substring(16,25));
  63. float lon =longitude/100000;
  64. float speedKPH = Float.parseFloat(T[0].substring(25,28));
  65. float headingDeg = Float.parseFloat(T[0].substring(28,31));
  66. String srcStr = T[0].substring(31,32);
  67. String ageStr = T[0].substring(32,33);
  68. double altitudeM = 0.0;
  69. double odomKM = 0.0;
  70. long gpioInput = 0L;
  71. String accountID ="demo";
  72.  
  73. GeoApiContext gtx = new GeoApiContext().setApiKey("AIzaSyBhfUqlLK2PScmdWnBjUvSAi59EWdLqVA4 ");
  74. try {
  75.  
  76. GeocodingResult[] gResp = GeocodingApi.newRequest(gtx).latlng(new LatLng(lat,lon)).await();
  77. System.out.println(gResp[0].formattedAddress);
  78. } catch (Exception e) {
  79. // TODO Auto-generated catch block
  80. e.printStackTrace();
  81. }
  82.  
  83.  
  84. System.out.println("gpstod:"+gpsTOD);
  85. System.out.println("lat:"+lat);
  86. System.out.println("lon:"+lon);
  87. System.out.println("speedKPH:"+speedKPH);
  88. System.out.println("headingDeg:"+headingDeg);
  89. System.out.println("srcStr:"+srcStr);
  90. System.out.println("ageStr:"+ageStr);
  91. System.out.println("altitudeM:"+altitudeM);
  92. System.out.println("odomKM:"+odomKM);
  93. System.out.println("gpioInput:"+gpioInput);
  94.  
  95. // try{
  96. //
  97. // Class.forName("com.mysql.jdbc.Driver");
  98. // Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/gts","gts","opengts");
  99. // Statement stmt=con.createStatement();
  100. // //stmt.executeQuery("insert into EventData(accountID,deviceID,timestamp,latitude,longitude,gpsAge,speedKPH,heading,altitude,odometerKM)values('"+ accountID +"','"+ mobileID +"','"+ lat +"','"+ lon +"','"+ ageStr +"','"+ speedKPH +"','"+ headingDeg +"','"+ altitudeM +"','"+ odomKM +"')");
  101. //
  102. // con.close();
  103. //
  104. // }
  105. // catch(Exception e)
  106. // {
  107. // System.out.println(e);
  108. // }
  109.  
  110.  
  111.  
  112.  
  113. }
  114.  
  115.  
  116. bufferedReader.close();
  117. }
  118. catch(FileNotFoundException ex) {
  119. System.out.println(
  120. "Unable to open file '" +
  121. fileName + "'");
  122. }
  123. catch(IOException ex) {
  124. System.out.println(
  125. "Error reading file '"
  126. + fileName + "'");
  127.  
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement