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;
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 +
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();
}
}
- 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;
}
}