]> average.org Git - WhereAmI.git/commitdiff
use http transport that does not crash,
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Thu, 2 Feb 2012 11:36:22 +0000 (15:36 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Thu, 2 Feb 2012 11:36:22 +0000 (15:36 +0400)
parse result into numerics

src/org/average/whereami/LastLocation.java

index bd25283111bb1c2e48bfd70401229045d45b0f25..230b8488fcc67b9b172384216c1aa7ec863d9d47 100644 (file)
@@ -1,14 +1,13 @@
 package org.average.whereami;
 
 import org.average.whereami.CredentialStore;
-//import org.average.whereami.WhereAmIAccessResource;
 
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+//import java.lang.Long;
 
+import com.google.api.client.extensions.android2.AndroidHttp;
 import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
 import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
+import com.google.api.client.http.HttpResponseException;
 import com.google.api.client.http.HttpTransport;
 import com.google.api.client.http.javanet.NetHttpTransport;
 import com.google.api.client.json.JsonFactory;
@@ -28,7 +27,7 @@ public final class LastLocation extends Oracle {
        private Latitude latitude;
 
        public LastLocation(final CredentialStore store) {
-               HttpTransport transport = new NetHttpTransport();
+               HttpTransport transport = AndroidHttp.newCompatibleTransport();
                JsonFactory jsonFactory = new JacksonFactory();
                AccessTokenResponse token = store.read();
                Log.v(TAG, "tokens - access: \"" + token.accessToken +
@@ -68,8 +67,14 @@ public final class LastLocation extends Oracle {
                        Latitude.CurrentLocation.Get request =
                                latitude.currentLocation().get();
                        request.setGranularity("best");
-                       Location currentLocation = request.execute();
-                       return locationMessage(currentLocation);
+                       Location cloc = request.execute();
+                       Double lat = Double.parseDouble(
+                                       cloc.getLatitude().toString());
+                       Double lon = Double.parseDouble(
+                                       cloc.getLongitude().toString());
+                       Long tsm = Long.parseLong(
+                                       cloc.getTimestampMs().toString());
+                       return locationMessage(lat, lon, tsm);
                 } catch (Exception ex) {
                        Log.v(TAG, "exception in getResult: " + ex);
                        ex.printStackTrace();
@@ -77,12 +82,9 @@ public final class LastLocation extends Oracle {
                 }
        }
 
-       private String locationMessage(Location currentLocation) {
-               Log.v(TAG, "entering locationMessage: " +
-                       currentLocation);
-               // lat = currentLocation.getLatitude();
-               // lon = currentLocation.getLongitude();
-               // tsm = currentLocation.getTimestampMs();
-               return "Current location: " + currentLocation;
+       private String locationMessage(Double lat, Double lon, Long tsm) {
+               Log.v(TAG, "entering locationMessage(" + lat +
+                               "," + lon + "," + tsm + ")");
+               return "Location: " + lat + "N " + lon + "E at " + tsm/1000;
        }
 }