@@ -97,8 +97,6 @@ private void startTracking() {
97
97
98
98
if (GooglePlayServicesUtil .isGooglePlayServicesAvailable (this ) == ConnectionResult .SUCCESS ) {
99
99
// TODO recheck this
100
- // mLocationClient = new LocationClient(this,this,this);
101
-
102
100
if (!mLocationClient .isConnected () || !mLocationClient .isConnecting ()) {
103
101
mLocationClient .connect ();
104
102
}
@@ -108,90 +106,10 @@ private void startTracking() {
108
106
}
109
107
110
108
protected void sendLocationDataToWebsite (Location location ) {
111
- // formatted for mysql datetime format
112
- DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
113
- dateFormat .setTimeZone (TimeZone .getDefault ());
114
- Date date = new Date (location .getTime ());
115
-
116
- SharedPreferences sharedPreferences = this .getSharedPreferences ("com.websmithing.gpstracker.prefs" , Context .MODE_PRIVATE );
117
- SharedPreferences .Editor editor = sharedPreferences .edit ();
118
-
119
- float totalDistanceInMeters = sharedPreferences .getFloat ("totalDistanceInMeters" , 0f );
120
-
121
- boolean firstTimeGettingPosition = sharedPreferences .getBoolean ("firstTimeGettingPosition" , true );
122
-
123
- if (firstTimeGettingPosition ) {
124
- editor .putBoolean ("firstTimeGettingPosition" , false );
125
- } else {
126
- Location previousLocation = new Location ("" );
127
- previousLocation .setLatitude (sharedPreferences .getFloat ("previousLatitude" , 0f ));
128
- previousLocation .setLongitude (sharedPreferences .getFloat ("previousLongitude" , 0f ));
129
-
130
- float distance = location .distanceTo (previousLocation );
131
- totalDistanceInMeters += distance ;
132
- editor .putFloat ("totalDistanceInMeters" , totalDistanceInMeters );
133
- }
134
-
135
- editor .putFloat ("previousLatitude" , (float )location .getLatitude ());
136
- editor .putFloat ("previousLongitude" , (float )location .getLongitude ());
137
- editor .apply ();
138
-
139
109
140
110
Log .i (TAG ,"sending location to server" );
141
111
mSocket .emit ("updatelocation" ,Double .toString (location .getLatitude ()));
142
112
// TODO use the following requestParams to create a JSON payload
143
- /* final RequestParams requestParams = new RequestParams();
144
- requestParams.put("latitude", Double.toString(location.getLatitude()));
145
- requestParams.put("longitude", Double.toString(location.getLongitude()));
146
-
147
- Double speedInMilesPerHour = location.getSpeed()* 2.2369;
148
- requestParams.put("speed", Integer.toString(speedInMilesPerHour.intValue()));
149
-
150
- try {
151
- requestParams.put("date", URLEncoder.encode(dateFormat.format(date), "UTF-8"));
152
- } catch (UnsupportedEncodingException e) {}
153
-
154
- requestParams.put("locationmethod", location.getProvider());
155
-
156
- if (totalDistanceInMeters > 0) {
157
- requestParams.put("distance", String.format("%.1f", totalDistanceInMeters / 1609)); // in miles,
158
- } else {
159
- requestParams.put("distance", "0.0"); // in miles
160
- }
161
-
162
- requestParams.put("username", sharedPreferences.getString("userName", ""));
163
- requestParams.put("phonenumber", sharedPreferences.getString("appID", "")); // uuid
164
- requestParams.put("sessionid", sharedPreferences.getString("sessionID", "")); // uuid
165
-
166
- Double accuracyInFeet = location.getAccuracy()* 3.28;
167
- requestParams.put("accuracy", Integer.toString(accuracyInFeet.intValue()));
168
-
169
- Double altitudeInFeet = location.getAltitude() * 3.28;
170
- requestParams.put("extrainfo", Integer.toString(altitudeInFeet.intValue()));
171
-
172
- requestParams.put("eventtype", "android");
173
-
174
- Float direction = location.getBearing();
175
- requestParams.put("direction", Integer.toString(direction.intValue()));*/
176
-
177
- //final String uploadWebsite = sharedPreferences.getString("defaultUploadWebsite", defaultUploadWebsite);
178
-
179
- /* TODO create a JSON payload of username, locationdata
180
- Emit the Payload
181
- */
182
-
183
- /*LoopjHttpClient.get(uploadWebsite, requestParams, new AsyncHttpResponseHandler() {
184
- @Override
185
- public void onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody) {
186
- LoopjHttpClient.debugLoopJ(TAG, "sendLocationDataToWebsite - success", uploadWebsite, requestParams, responseBody, headers, statusCode, null);
187
- stopSelf();
188
- }
189
- @Override
190
- public void onFailure(int statusCode, org.apache.http.Header[] headers, byte[] errorResponse, Throwable e) {
191
- LoopjHttpClient.debugLoopJ(TAG, "sendLocationDataToWebsite - failure", uploadWebsite, requestParams, errorResponse, headers, statusCode, e);
192
- stopSelf();
193
- }
194
- });*/
195
113
}
196
114
197
115
@ Override
@@ -210,11 +128,7 @@ public void onLocationChanged(Location location) {
210
128
if (location != null ) {
211
129
Log .e (TAG , "position: " + location .getLatitude () + ", " + location .getLongitude () + " accuracy: " + location .getAccuracy ());
212
130
213
- // we have our desired accuracy of 500 meters so lets quit this service,
214
- // onDestroy will be called and stop our location uodates
215
131
if (location .getAccuracy () < 500.0f ) {
216
- // TODO no need to stop location updates in our case
217
- // stopLocationUpdates();
218
132
sendLocationDataToWebsite (location );
219
133
}
220
134
}
@@ -238,26 +152,20 @@ public void onConnected(Bundle bundle) {
238
152
Log .d (TAG , "onConnected" );
239
153
240
154
mLocationRequest = LocationRequest .create ();
241
- mLocationRequest .setInterval (1000 ); // milliseconds
242
- mLocationRequest .setFastestInterval (1000 ); // the fastest rate in milliseconds at which your app can handle location updates
155
+ mLocationRequest .setInterval (5000 ); // milliseconds
243
156
mLocationRequest .setPriority (LocationRequest .PRIORITY_HIGH_ACCURACY );
244
157
245
- //mLocationClient.requestLocationUpdates(mLocationRequest, this);
246
158
LocationServices .FusedLocationApi .requestLocationUpdates (mLocationClient , mLocationRequest , this );
247
159
248
160
// connect to socket for upload
249
161
mSocket .connect ();
250
-
251
162
}
252
163
253
164
/**
254
165
* Called by Location Services if the connection to the
255
166
* location client drops because of an error.
256
167
*/
257
168
258
- /*
259
- * TODO a good idea would be to try to restart/reconnect the service using alarm manager
260
- */
261
169
@ Override
262
170
public void onConnectionSuspended (int i ) {
263
171
Log .e (TAG , "onDisconnected" );
@@ -294,11 +202,6 @@ public void call(Object... args) {
294
202
new Handler (Looper .getMainLooper ()).post (new Runnable () {
295
203
@ Override
296
204
public void run () {
297
- /*
298
- Intent notifyIntent = new Intent("eatgreedi.mobile.com.egm.NotifyUser");
299
- notifyIntent.putExtra("message","some message");
300
- sendBroadcast(notifyIntent);
301
- */
302
205
Toast .makeText (getApplicationContext (),
303
206
"Some Message Received" , Toast .LENGTH_LONG ).show ();
304
207
0 commit comments