Skip to content

Instantly share code, notes, and snippets.

@ecgreb
Last active February 1, 2017 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecgreb/e405f8ec72bbc4fd479632429ce43f2e to your computer and use it in GitHub Desktop.
Save ecgreb/e405f8ec72bbc4fd479632429ce43f2e to your computer and use it in GitHub Desktop.
public class UserLocationStore {
private final Context context;
public UserLocationStore(Context context) {
this.context = context;
}
public UserLocation getLocation() {
if (ContextCompat.checkSelfPermission(context,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
UserLocation userLocation = new UserLocation("device");
// Fetch current device location from the LocationManager.
return userLocation;
} else {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS);
OkHttpClient okHttpClient = builder.build();
UserLocation userLocation = new UserLocation("web");
// Fetch user's default location from a web service.
return userLocation;
}
}
public class UserLocation {
private final String source;
private double lat;
private double lon;
public UserLocation(String source) {
this.source = source;
}
public String getSource() {
return source;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment