Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.google.maps;
- import java.io.*;
- import java.net.*;
- import java.util.*;
- import java.sql.*;
- import java.sql.Statement;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import com.google.maps.internal.ApiConfig;
- import com.google.maps.internal.ApiResponse;
- import com.google.maps.model.GeocodingResult;
- import com.google.maps.model.LatLng;
- public class FileHandler
- {
- public static void main(String [] args) {
- String fileName = "ascii_file";
- String line = null;
- try {
- FileReader fileReader =
- new FileReader(fileName);
- BufferedReader bufferedReader =
- new BufferedReader(fileReader);
- while((line = bufferedReader.readLine()) != null) {
- System.out.println(line);
- int se = line.endsWith("<")? (line.length() - 1) : line.length();
- System.out.println("se-----------------------------"+se);
- String parsedstring = line.substring(1,se);
- System.out.println("parsedString"+parsedstring);
- String T[] = parsedstring.split(";");
- System.out.println("ttttt-----------------------------"+T[0]);
- String mobileID = null;
- for (int i = 1; i < T.length; i++) {
- if (T[i].startsWith("ID=")) {
- mobileID = T[i].substring(3);
- System.out.println("mobileID-----------------"+mobileID);
- break;
- }}
- int gpsTOD = Integer.parseInt(T[0].substring( 3, 8));
- float latitude = Float.parseFloat(T[0].substring( 8,16));
- float lat =latitude/100000;
- float longitude = Float.parseFloat(T[0].substring(16,25));
- float lon =longitude/100000;
- float speedKPH = Float.parseFloat(T[0].substring(25,28));
- float headingDeg = Float.parseFloat(T[0].substring(28,31));
- String srcStr = T[0].substring(31,32);
- String ageStr = T[0].substring(32,33);
- double altitudeM = 0.0;
- double odomKM = 0.0;
- long gpioInput = 0L;
- String accountID ="demo";
- GeoApiContext gtx = new GeoApiContext().setApiKey("AIzaSyBhfUqlLK2PScmdWnBjUvSAi59EWdLqVA4 ");
- try {
- GeocodingResult[] gResp = GeocodingApi.newRequest(gtx).latlng(new LatLng(lat,lon)).await();
- System.out.println(gResp[0].formattedAddress);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("gpstod:"+gpsTOD);
- System.out.println("lat:"+lat);
- System.out.println("lon:"+lon);
- System.out.println("speedKPH:"+speedKPH);
- System.out.println("headingDeg:"+headingDeg);
- System.out.println("srcStr:"+srcStr);
- System.out.println("ageStr:"+ageStr);
- System.out.println("altitudeM:"+altitudeM);
- System.out.println("odomKM:"+odomKM);
- System.out.println("gpioInput:"+gpioInput);
- // try{
- //
- // Class.forName("com.mysql.jdbc.Driver");
- // Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/gts","gts","opengts");
- // Statement stmt=con.createStatement();
- // //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 +"')");
- //
- // con.close();
- //
- // }
- // catch(Exception e)
- // {
- // System.out.println(e);
- // }
- }
- bufferedReader.close();
- }
- catch(FileNotFoundException ex) {
- System.out.println(
- "Unable to open file '" +
- fileName + "'");
- }
- catch(IOException ex) {
- System.out.println(
- "Error reading file '"
- + fileName + "'");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement