diff --git a/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/GpsHelper.java b/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/GpsHelper.java index 2b1fc68..96cabdc 100644 --- a/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/GpsHelper.java +++ b/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/GpsHelper.java @@ -2,7 +2,7 @@ // GpsHelper.java // GpsTracker // -// Created by Nick Fox on 12/1/13. +// Created by Nick Fox on 11/7/13. // Copyright (c) 2013 Nick Fox. All rights reserved. // @@ -20,7 +20,6 @@ private float distance = 0; private int azimuth = 0; private String uploadWebsite; - private String queryString; private GpsTracker midlet; private int interval; protected Calendar currentTime; @@ -131,27 +130,43 @@ speed = location.getSpeed(); } - queryString = "?lat=" + String.valueOf(qualifiedCoordinates.getLatitude()) + /* example url + http://www.websmithing.com/gpstracker2/getgooglemap2.php?lat=47.473349&lng=-122.025035&mph=137&dir=0&mi=0& + dt=2008-04-17%2012:07:02&lm=0&h=291&w=240&zm=12&dis=25&pn=momosity&sid=11137&acc=95&iv=yes&info=momostuff + + string defaultUploadWebsite = "http://www.websmithing.com/gpstracker2/getgooglemap3.php"; + + new KeyValuePair("lat", latitude), + new KeyValuePair("lng", longitude), + new KeyValuePair("mph", speed), + new KeyValuePair("dir", direction), + new KeyValuePair("dt", DateTime.Now.ToString(@"yyyy-MM-dd\%20HH:mm:ss")), // formatted for mysql datetime format), + new KeyValuePair("lm", locationMethod), + new KeyValuePair("dis", (totalDistanceInMeters / 1609).ToString("0.0")), // in miles + new KeyValuePair("pn", "momo1"), //Windows.Phone.System.Analytics.HostInformation.PublisherHostId), + new KeyValuePair("sid", sessionID), + new KeyValuePair("acc", accuracy), + new KeyValuePair("iv", "yes"), + new KeyValuePair("info", "windowsphone-" + httpCount.ToString()) + */ + + String gpsData = "lat=" + String.valueOf(qualifiedCoordinates.getLatitude()) + "&lng=" + String.valueOf(qualifiedCoordinates.getLongitude()) - + "&mph=" + String.valueOf((int)(speed/1609*3600)) + + "&mph=" + String.valueOf((int)(speed/1609*3600)) // in miles per hour + "&dir=" + String.valueOf(azimuth) - + "&dis=" + String.valueOf((int)(distance/1609)) - + "&dt=" + d.toString() + + "&dt=2008-04-17%2012:07:02" // + d.toString() + "&lm=" + location.getLocationMethod() + + "&dis=" + String.valueOf((int)(distance/1609)) // in miles + "&pn=" + midlet.phoneNumber - + "&sid=" + String.valueOf(sessionID) - + "&acc=" + String.valueOf((int)(qualifiedCoordinates.getHorizontalAccuracy()*3.28)) - + "&iv=" + String.valueOf(location.isValid()) - + "&info=" + location.getExtraInfo("text/plain") - + "&zm=" + midlet.zoomLevel - + "&h=" + midlet.height - + "&w=" + midlet.width; + + "&sid=" + String.valueOf(sessionID) // guid? + + "&acc=" + String.valueOf((int)(qualifiedCoordinates.getHorizontalAccuracy()*3.28)) // in feet + + "&iv=yes" + + "&info=javaMe-" + location.getExtraInfo("text/plain"); // with our query string built, we create a networker object to send the - // query to our website and get the map image and update the DB - NetWorker worker = new NetWorker(midlet, uploadWebsite); - worker.getUrl(queryString); - + // gps data to our website and update the DB + NetWorker netWorker = new NetWorker(midlet, uploadWebsite); + netWorker.postGpsData(gpsData); } } catch (Exception e) { diff --git a/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/GpsTracker.java b/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/GpsTracker.java index f30f850..63b01d8 100644 --- a/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/GpsTracker.java +++ b/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/GpsTracker.java @@ -2,7 +2,7 @@ // GpsTracker.java // GpsTracker // -// Created by Nick Fox on 12/1/13. +// Created by Nick Fox on 11/7/13. // Copyright (c) 2013 Nick Fox. All rights reserved. // @@ -34,7 +34,7 @@ private GpsHelper gps; private String uploadWebsite; - private String defaultUploadWebsite = "http://www.websmithing.com/gpstracker/GetGoogleMap2.php"; + private String defaultUploadWebsite = "http://www.websmithing.com/gpstracker2/getgooglemap3.php"; protected String phoneNumber; protected String zoomLevel; diff --git a/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/NetWorker.java b/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/NetWorker.java index 8fe5191..b38a043 100644 --- a/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/NetWorker.java +++ b/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/NetWorker.java @@ -2,7 +2,7 @@ // NetWorker.java // GpsTracker // -// Created by Nick Fox on 12/1/13. +// Created by Nick Fox on 11/7/13. // Copyright (c) 2013 Nick Fox. All rights reserved. // @@ -10,7 +10,6 @@ import javax.microedition.io.*; import java.io.*; -import javax.microedition.lcdui.Image; public class NetWorker { private GpsTracker midlet; @@ -22,75 +21,47 @@ this.uploadWebsite = UploadWebsite; } - public void getUrl(String queryString) { - queryString = URLencodeSpaces(queryString); - String url = uploadWebsite + queryString; - HttpConnection httpConn = null; - InputStream inputStream = null; - DataInputStream iStrm = null; - ByteArrayOutputStream bStrm = null; - Image im = null; - + public void postGpsData(String queryString) { + queryString = urlEncodeString(queryString); + HttpConnection httpConnection = null; + DataOutputStream dataOutputStream = null; + try{ - httpConn = (HttpConnection)Connector.open(url); - - if(httpConn.getResponseCode() == HttpConnection.HTTP_OK){ - inputStream = httpConn.openInputStream(); - iStrm = new DataInputStream(inputStream); + httpConnection = (HttpConnection)Connector.open(uploadWebsite); + httpConnection.setRequestMethod(HttpConnection.POST); + httpConnection.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0"); + httpConnection.setRequestProperty("Content-Language", "en-US"); + httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + httpConnection.setRequestProperty("Content-Length", String.valueOf(queryString.length())); + + dataOutputStream = new DataOutputStream(httpConnection.openOutputStream()); + dataOutputStream.write(queryString.getBytes()); + + // some mobile devices have unexpected behavior with flush(), test before using + //dataOutputStream.flush(); - byte imageData[]; - int length = (int)httpConn.getLength(); - - if(length != -1) { - imageData = new byte[length]; - iStrm.readFully(imageData); - } - else { //Length not available - bStrm = new ByteArrayOutputStream(); - int ch; - - while((ch = iStrm.read())!= -1) { - bStrm.write(ch); - } - imageData = bStrm.toByteArray(); - - } - im = Image.createImage(imageData, 0, imageData.length); + if(httpConnection.getResponseCode() != HttpConnection.HTTP_OK){ + midlet.log("NetWorker.postGpsData responseCode: " + httpConnection.getResponseCode()); } - else { - midlet.log("NetWorker.getUrl responseCode: " + httpConn.getResponseCode()); - } - } catch (Exception e) { - midlet.log("NetWorker.getUrl: " + e); + midlet.log("NetWorker.postGpsData error: " + e); } - finally{ // Clean up + finally{ // clean up try{ - if(bStrm != null) - bStrm.close(); - if(iStrm != null) - iStrm.close(); - if(inputStream != null) - inputStream.close(); - if(httpConn != null) - httpConn.close(); + if(httpConnection != null) + httpConnection.close(); + if(dataOutputStream != null) + dataOutputStream.close(); } catch(Exception e){} } // if we have successfully gotten a map image, then we want to display it - if( im == null) { - midlet.showMap(false); - } - else { - midlet.im = im; - midlet.showMap(true); - } - + midlet.showMap(false); } - // http://forum.java.sun.com/thread.jspa?threadID=341790&messageID=1408555 - private String URLencodeSpaces(String s) + + private String urlEncodeString(String s) { if (s != null) { StringBuffer tmp = new StringBuffer(); diff --git a/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/RmsHelper.java b/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/RmsHelper.java index 08e624a..6a904c6 100644 --- a/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/RmsHelper.java +++ b/phoneClients/javaMe/build/preprocessed/com/websmithing/gpstracker/RmsHelper.java @@ -2,7 +2,7 @@ // RmsHelper.java // GpsTracker // -// Created by Nick Fox on 12/1/13. +// Created by Nick Fox on 11/7/13. // Copyright (c) 2013 Nick Fox. All rights reserved. // diff --git a/phoneClients/javaMe/dist/GpsTracker.jad b/phoneClients/javaMe/dist/GpsTracker.jad index fec3188..793c12a 100644 --- a/phoneClients/javaMe/dist/GpsTracker.jad +++ b/phoneClients/javaMe/dist/GpsTracker.jad @@ -1,5 +1,5 @@ MIDlet-1: GpsTracker, , com.websmithing.gpstracker.GpsTracker -MIDlet-Jar-Size: 12990 +MIDlet-Jar-Size: 12646 MIDlet-Jar-URL: GpsTracker.jar MIDlet-Name: GpsTracker MIDlet-Vendor: Vendor diff --git a/phoneClients/javaMe/dist/nbrun3504791845681826142/GpsTracker.jad b/phoneClients/javaMe/dist/nbrun3504791845681826142/GpsTracker.jad deleted file mode 100644 index fec3188..0000000 --- a/phoneClients/javaMe/dist/nbrun3504791845681826142/GpsTracker.jad +++ /dev/null @@ -1,8 +0,0 @@ -MIDlet-1: GpsTracker, , com.websmithing.gpstracker.GpsTracker -MIDlet-Jar-Size: 12990 -MIDlet-Jar-URL: GpsTracker.jar -MIDlet-Name: GpsTracker -MIDlet-Vendor: Vendor -MIDlet-Version: 1.0 -MicroEdition-Configuration: CLDC-1.1 -MicroEdition-Profile: MIDP-2.1 diff --git a/phoneClients/javaMe/src/com/websmithing/gpstracker/GpsHelper.java b/phoneClients/javaMe/src/com/websmithing/gpstracker/GpsHelper.java index f88649a..96cabdc 100644 --- a/phoneClients/javaMe/src/com/websmithing/gpstracker/GpsHelper.java +++ b/phoneClients/javaMe/src/com/websmithing/gpstracker/GpsHelper.java @@ -20,7 +20,6 @@ private float distance = 0; private int azimuth = 0; private String uploadWebsite; - private String queryString; private GpsTracker midlet; private int interval; protected Calendar currentTime; @@ -131,27 +130,43 @@ speed = location.getSpeed(); } - queryString = "?lat=" + String.valueOf(qualifiedCoordinates.getLatitude()) + /* example url + http://www.websmithing.com/gpstracker2/getgooglemap2.php?lat=47.473349&lng=-122.025035&mph=137&dir=0&mi=0& + dt=2008-04-17%2012:07:02&lm=0&h=291&w=240&zm=12&dis=25&pn=momosity&sid=11137&acc=95&iv=yes&info=momostuff + + string defaultUploadWebsite = "http://www.websmithing.com/gpstracker2/getgooglemap3.php"; + + new KeyValuePair("lat", latitude), + new KeyValuePair("lng", longitude), + new KeyValuePair("mph", speed), + new KeyValuePair("dir", direction), + new KeyValuePair("dt", DateTime.Now.ToString(@"yyyy-MM-dd\%20HH:mm:ss")), // formatted for mysql datetime format), + new KeyValuePair("lm", locationMethod), + new KeyValuePair("dis", (totalDistanceInMeters / 1609).ToString("0.0")), // in miles + new KeyValuePair("pn", "momo1"), //Windows.Phone.System.Analytics.HostInformation.PublisherHostId), + new KeyValuePair("sid", sessionID), + new KeyValuePair("acc", accuracy), + new KeyValuePair("iv", "yes"), + new KeyValuePair("info", "windowsphone-" + httpCount.ToString()) + */ + + String gpsData = "lat=" + String.valueOf(qualifiedCoordinates.getLatitude()) + "&lng=" + String.valueOf(qualifiedCoordinates.getLongitude()) - + "&mph=" + String.valueOf((int)(speed/1609*3600)) + + "&mph=" + String.valueOf((int)(speed/1609*3600)) // in miles per hour + "&dir=" + String.valueOf(azimuth) - + "&dis=" + String.valueOf((int)(distance/1609)) - + "&dt=" + d.toString() + + "&dt=2008-04-17%2012:07:02" // + d.toString() + "&lm=" + location.getLocationMethod() + + "&dis=" + String.valueOf((int)(distance/1609)) // in miles + "&pn=" + midlet.phoneNumber - + "&sid=" + String.valueOf(sessionID) - + "&acc=" + String.valueOf((int)(qualifiedCoordinates.getHorizontalAccuracy()*3.28)) - + "&iv=" + String.valueOf(location.isValid()) - + "&info=" + location.getExtraInfo("text/plain") - + "&zm=" + midlet.zoomLevel - + "&h=" + midlet.height - + "&w=" + midlet.width; + + "&sid=" + String.valueOf(sessionID) // guid? + + "&acc=" + String.valueOf((int)(qualifiedCoordinates.getHorizontalAccuracy()*3.28)) // in feet + + "&iv=yes" + + "&info=javaMe-" + location.getExtraInfo("text/plain"); // with our query string built, we create a networker object to send the - // query to our website and get the map image and update the DB - NetWorker worker = new NetWorker(midlet, uploadWebsite); - worker.getUrl(queryString); - + // gps data to our website and update the DB + NetWorker netWorker = new NetWorker(midlet, uploadWebsite); + netWorker.postGpsData(gpsData); } } catch (Exception e) { diff --git a/phoneClients/javaMe/src/com/websmithing/gpstracker/GpsTracker.java b/phoneClients/javaMe/src/com/websmithing/gpstracker/GpsTracker.java index e69d4c4..63b01d8 100644 --- a/phoneClients/javaMe/src/com/websmithing/gpstracker/GpsTracker.java +++ b/phoneClients/javaMe/src/com/websmithing/gpstracker/GpsTracker.java @@ -34,7 +34,7 @@ private GpsHelper gps; private String uploadWebsite; - private String defaultUploadWebsite = "http://www.websmithing.com/gpstracker/GetGoogleMap2.php"; + private String defaultUploadWebsite = "http://www.websmithing.com/gpstracker2/getgooglemap3.php"; protected String phoneNumber; protected String zoomLevel; diff --git a/phoneClients/javaMe/src/com/websmithing/gpstracker/NetWorker.java b/phoneClients/javaMe/src/com/websmithing/gpstracker/NetWorker.java index c509a8f..b38a043 100644 --- a/phoneClients/javaMe/src/com/websmithing/gpstracker/NetWorker.java +++ b/phoneClients/javaMe/src/com/websmithing/gpstracker/NetWorker.java @@ -10,7 +10,6 @@ import javax.microedition.io.*; import java.io.*; -import javax.microedition.lcdui.Image; public class NetWorker { private GpsTracker midlet; @@ -22,75 +21,47 @@ this.uploadWebsite = UploadWebsite; } - public void getUrl(String queryString) { - queryString = URLencodeSpaces(queryString); - String url = uploadWebsite + queryString; - HttpConnection httpConn = null; - InputStream inputStream = null; - DataInputStream iStrm = null; - ByteArrayOutputStream bStrm = null; - Image im = null; - + public void postGpsData(String queryString) { + queryString = urlEncodeString(queryString); + HttpConnection httpConnection = null; + DataOutputStream dataOutputStream = null; + try{ - httpConn = (HttpConnection)Connector.open(url); - - if(httpConn.getResponseCode() == HttpConnection.HTTP_OK){ - inputStream = httpConn.openInputStream(); - iStrm = new DataInputStream(inputStream); + httpConnection = (HttpConnection)Connector.open(uploadWebsite); + httpConnection.setRequestMethod(HttpConnection.POST); + httpConnection.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0"); + httpConnection.setRequestProperty("Content-Language", "en-US"); + httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + httpConnection.setRequestProperty("Content-Length", String.valueOf(queryString.length())); + + dataOutputStream = new DataOutputStream(httpConnection.openOutputStream()); + dataOutputStream.write(queryString.getBytes()); + + // some mobile devices have unexpected behavior with flush(), test before using + //dataOutputStream.flush(); - byte imageData[]; - int length = (int)httpConn.getLength(); - - if(length != -1) { - imageData = new byte[length]; - iStrm.readFully(imageData); - } - else { //Length not available - bStrm = new ByteArrayOutputStream(); - int ch; - - while((ch = iStrm.read())!= -1) { - bStrm.write(ch); - } - imageData = bStrm.toByteArray(); - - } - im = Image.createImage(imageData, 0, imageData.length); + if(httpConnection.getResponseCode() != HttpConnection.HTTP_OK){ + midlet.log("NetWorker.postGpsData responseCode: " + httpConnection.getResponseCode()); } - else { - midlet.log("NetWorker.getUrl responseCode: " + httpConn.getResponseCode()); - } - } catch (Exception e) { - midlet.log("NetWorker.getUrl: " + e); + midlet.log("NetWorker.postGpsData error: " + e); } - finally{ // Clean up + finally{ // clean up try{ - if(bStrm != null) - bStrm.close(); - if(iStrm != null) - iStrm.close(); - if(inputStream != null) - inputStream.close(); - if(httpConn != null) - httpConn.close(); + if(httpConnection != null) + httpConnection.close(); + if(dataOutputStream != null) + dataOutputStream.close(); } catch(Exception e){} } // if we have successfully gotten a map image, then we want to display it - if( im == null) { - midlet.showMap(false); - } - else { - midlet.im = im; - midlet.showMap(true); - } - + midlet.showMap(false); } - // http://forum.java.sun.com/thread.jspa?threadID=341790&messageID=1408555 - private String URLencodeSpaces(String s) + + private String urlEncodeString(String s) { if (s != null) { StringBuffer tmp = new StringBuffer(); diff --git a/phoneClients/windowsPhone/GPSTracker/MainPage.xaml.cs b/phoneClients/windowsPhone/GPSTracker/MainPage.xaml.cs index 2971fd2..f90912e 100644 --- a/phoneClients/windowsPhone/GPSTracker/MainPage.xaml.cs +++ b/phoneClients/windowsPhone/GPSTracker/MainPage.xaml.cs @@ -81,14 +81,14 @@ { new KeyValuePair("lat", latitude), new KeyValuePair("lng", longitude), - new KeyValuePair("mph", speed), + new KeyValuePair("mph", speed), // in miles per hour new KeyValuePair("dir", direction), new KeyValuePair("dt", DateTime.Now.ToString(@"yyyy-MM-dd\%20HH:mm:ss")), // formatted for mysql datetime format), new KeyValuePair("lm", locationMethod), new KeyValuePair("dis", (totalDistanceInMeters / 1609).ToString("0.0")), // in miles new KeyValuePair("pn", "momo1"), //Windows.Phone.System.Analytics.HostInformation.PublisherHostId), - new KeyValuePair("sid", sessionID), - new KeyValuePair("acc", accuracy), + new KeyValuePair("sid", sessionID), // guid + new KeyValuePair("acc", accuracy), // in meters new KeyValuePair("iv", "yes"), new KeyValuePair("info", "windowsphone-" + httpCount.ToString()) });