Last active
February 1, 2017 01:05
-
-
Save ecgreb/e405f8ec72bbc4fd479632429ce43f2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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