Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialanirudh erabelly
Courses Plus Student 535 PointsTime zone problem in API
I'm not in the time zone america/losangeles but i'm getting the same latitude and longitude coordinates how can i make the app automatically detect users location and display weather forecast of that place.
1 Answer
Ragesh Kanagaraj
3,637 PointsYou need to use Googleplay services & LocationServices to get access to users Longitude and Latitude. Once you get it pass those are parameters to the URL.
I have attached a small code snippet from my project just for your reference and also refer this blog, Ben has given a great explanation to handle users Location. Here is the link
My Code :
public void onConnected(Bundle bundle) {
Log.i(TAG, "Location Service Connected");
Location location=LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (location == null) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
Log.e(TAG,"Location is NULL");
}
else {
handleNewLocation(location);
}
}
private void handleNewLocation(Location location) {
double latitude=location.getLatitude();
double longitude=location.getLongitude();
Log.i(TAG,"Latitude : "+location.getLatitude());
Log.i(TAG,"Longitde : "+location.getLongitude()); ```