From: Eugene Crosser Date: Thu, 2 Feb 2012 11:36:22 +0000 (+0400) Subject: use http transport that does not crash, X-Git-Url: http://average.org/gitweb/?a=commitdiff_plain;h=691c01af7b7c46b51d80d6b77656f9cda38d2b86;p=WhereAmI.git use http transport that does not crash, parse result into numerics --- diff --git a/src/org/average/whereami/LastLocation.java b/src/org/average/whereami/LastLocation.java index bd25283..230b848 100644 --- a/src/org/average/whereami/LastLocation.java +++ b/src/org/average/whereami/LastLocation.java @@ -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; } }