📄 track.java
字号:
latitude |= 0x000000ff & bytes[2];
latitude |= (latitude & 0x00800000) != 0 ? 0xff000000 : 0;
int longitude = 0x00ff0000 & (bytes[3] << 16);
longitude |= 0x0000ff00 & (bytes[4] << 8);
longitude |= 0x000000ff & bytes[5];
longitude |= (longitude & 0x00800000) != 0 ? 0xff000000 : 0;
if (recordId == 1) {
out.write(" <Placemark>\r\n".getBytes());
out.write(" <name>Start</name>\r\n".getBytes());
out.write(" <styleUrl>#waypoint</styleUrl>\r\n".getBytes());
out.write(" <Point>\r\n".getBytes());
out.write(" <coordinates>\r\n".getBytes());
writeKmlPosition(out, latitude, longitude);
out.write(" </coordinates>\r\n".getBytes());
out.write(" </Point>\r\n".getBytes());
out.write(" </Placemark>\r\n".getBytes());
out.write(" <Placemark>\r\n".getBytes());
out.write(" <name>Track</name>\r\n".getBytes());
out.write(" <styleUrl>#track</styleUrl>\r\n".getBytes());
out.write(" <LineString>\r\n".getBytes());
out.write(" <coordinates>\r\n".getBytes());
}
writeKmlPosition(out, latitude, longitude);
if (recordId == numRecords) {
out.write(" </coordinates>\r\n".getBytes());
out.write(" </LineString>\r\n".getBytes());
out.write(" </Placemark>\r\n".getBytes());
out.write(" <Placemark>\r\n".getBytes());
out.write(" <name>End</name>\r\n".getBytes());
out.write(" <styleUrl>#waypoint</styleUrl>\r\n".getBytes());
out.write(" <Point>\r\n".getBytes());
out.write(" <coordinates>\r\n".getBytes());
writeKmlPosition(out, latitude, longitude);
out.write(" </coordinates>\r\n".getBytes());
out.write(" </Point>\r\n".getBytes());
out.write(" </Placemark>\r\n".getBytes());
}
if (gauge != null)
gauge.setValue(recordId * 10 / numRecords);
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException ex) { }
}
out.write(" </Document>\r\n".getBytes());
out.write("</kml>\r\n".getBytes());
} finally {
try {
if (recordStore != null)
recordStore.closeRecordStore();
} catch (Exception e) { }
}
}
private static void writeKmlPosition(DataOutputStream out, int latitude, int longitude) throws IOException {
out.write(new Float(longitude).Div(DEGREESTOINT).toString().getBytes());
out.write(",".getBytes());
out.write(new Float(latitude).Div(DEGREESTOINT).toString().getBytes());
out.write(",0\r\n".getBytes());
}
private static void writeGpx(DataOutputStream out, String trackName, Gauge gauge) throws IOException, RecordStoreException {
RecordStore recordStore = null;
try {
out.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n".getBytes());
out.write("<gpx version=\"1.0\"\r\n".getBytes());
out.write("creator=\"GpsTrack - http://www.qcontinuum.org/gpstrack\"\r\n".getBytes());
out.write("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"".getBytes());
out.write(" xmlns=\"http://www.topografix.com/GPX/1/0\"\r\n".getBytes());
out.write("xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\r\n".getBytes());
out.write("<trk>\r\n".getBytes());
out.write("<name>".getBytes());
out.write(trackName.getBytes());
out.write("</name>\r\n".getBytes());
out.write("<trkseg>\r\n".getBytes());
recordStore = RecordStore.openRecordStore(trackName, false);
int numRecords = recordStore.getNumRecords();
byte[] bytes = new byte[6];
for (int recordId = 1; recordId <= numRecords; recordId++) {
recordStore.getRecord(recordId, bytes, 0);
int latitude = 0x00ff0000 & (bytes[0] << 16);
latitude |= 0x0000ff00 & (bytes[1] << 8);
latitude |= 0x000000ff & bytes[2];
latitude |= (latitude & 0x00800000) != 0 ? 0xff000000 : 0;
int longitude = 0x00ff0000 & (bytes[3] << 16);
longitude |= 0x0000ff00 & (bytes[4] << 8);
longitude |= 0x000000ff & bytes[5];
longitude |= (longitude & 0x00800000) != 0 ? 0xff000000 : 0;
out.write("<trkpt lat=\"".getBytes());
out.write(new Float(latitude).Div(DEGREESTOINT).toString().getBytes());
out.write("\" lon=\"".getBytes());
out.write(new Float(longitude).Div(DEGREESTOINT).toString().getBytes());
out.write("\"></trkpt>\r\n".getBytes());
if (gauge != null)
gauge.setValue(recordId * 10 / numRecords);
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException ex) { }
}
out.write("</trkseg>\r\n".getBytes());
out.write("</trk>\r\n".getBytes());
out.write("</gpx>\r\n".getBytes());
} finally {
try {
if (recordStore != null)
recordStore.closeRecordStore();
} catch (Exception e) { }
}
}
private static void writeCsv(DataOutputStream out, String trackName, Gauge gauge) throws IOException, RecordStoreException {
RecordStore recordStore = null;
try {
out.write("latitude,longitude\r\n".getBytes());
recordStore = RecordStore.openRecordStore(trackName, false);
int numRecords = recordStore.getNumRecords();
byte[] bytes = new byte[6];
for (int recordId = 1; recordId <= numRecords; recordId++) {
recordStore.getRecord(recordId, bytes, 0);
int latitude = 0x00ff0000 & (bytes[0] << 16);
latitude |= 0x0000ff00 & (bytes[1] << 8);
latitude |= 0x000000ff & bytes[2];
latitude |= (latitude & 0x00800000) != 0 ? 0xff000000 : 0;
int longitude = 0x00ff0000 & (bytes[3] << 16);
longitude |= 0x0000ff00 & (bytes[4] << 8);
longitude |= 0x000000ff & bytes[5];
longitude |= (longitude & 0x00800000) != 0 ? 0xff000000 : 0;
out.write(new Float(latitude).Div(DEGREESTOINT).toString().getBytes());
out.write(",".getBytes());
out.write(new Float(longitude).Div(DEGREESTOINT).toString().getBytes());
out.write("\r\n".getBytes());
if (gauge != null)
gauge.setValue(recordId * 10 / numRecords);
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException ex) { }
}
} finally {
try {
if (recordStore != null)
recordStore.closeRecordStore();
} catch (Exception e) { }
}
}
private static void writeBinary(DataOutputStream out, String trackName, Gauge gauge) throws IOException, RecordStoreException {
RecordStore recordStore = null;
try {
recordStore = RecordStore.openRecordStore(trackName, false);
int numRecords = recordStore.getNumRecords();
byte[] bytes = new byte[6];
for (int recordId = 1; recordId <= numRecords; recordId++) {
recordStore.getRecord(recordId, bytes, 0);
out.write(bytes);
if (gauge != null)
gauge.setValue(recordId * 10 / numRecords);
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException ex) { }
}
} finally {
try {
if (recordStore != null)
recordStore.closeRecordStore();
} catch (Exception e) { }
}
}
public static void writeHttp(int format, String trackName, String userName, Gauge gauge) throws IOException, RecordStoreException {
HttpConnection httpConnection = null;
DataOutputStream dataOutputStream = null;
Preferences preferences = GpsTrack.getPreferences();
try {
httpConnection =(HttpConnection)
Connector.open("http://qcontinuum.org/scripts/gpstrack.cgi");
httpConnection.setRequestMethod(HttpConnection.POST);
httpConnection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
String boundary = "AaB03x";
httpConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
dataOutputStream = new DataOutputStream(httpConnection.openDataOutputStream());
dataOutputStream.write(("--" + boundary + "\r\n").getBytes());
writeHttpParam("platform", System.getProperty("microedition.platform"), dataOutputStream);
dataOutputStream.write(("--" + boundary + "\r\n").getBytes());
writeHttpParam("gps", preferences.getBluetoothHost(), dataOutputStream);
dataOutputStream.write(("--" + boundary + "\r\n").getBytes());
writeHttpParam("format", getFormatName(format), dataOutputStream);
dataOutputStream.write(("--" + boundary + "\r\n").getBytes());
writeHttpParam("email", userName, dataOutputStream);
dataOutputStream.write(("--" + boundary + "\r\n").getBytes());
writeHttpFile("file", trackName, dataOutputStream, gauge);
dataOutputStream.write(("--" + boundary + "--\r\n").getBytes());
} finally {
try {
if (dataOutputStream != null)
dataOutputStream.close();
if (httpConnection != null)
httpConnection.close();
} catch (Exception e) { }
}
}
private static void writeHttpParam(String name, String value, DataOutputStream out) {
try {
out.write(("Content-Disposition: form-data; name=\"" + name + "\"\r\n\r\n").getBytes());
if (value != null)
out.write(value.getBytes());
out.write(("\r\n").getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
private static void writeHttpFile(String name, String trackName, DataOutputStream out, Gauge gauge)
{
try {
out.write(("Content-Disposition: form-data; name=\"" + name + "\"; filename=\""
+ trackName + "\"\r\n").getBytes());
out.write(("Content-Type: application/octet-stream" + "\r\n\r\n").getBytes());
Track.write(FORMAT_BINARY, out, trackName, gauge);
out.write(("\r\n").getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -