views:

116

answers:

2

Is there a way to obtain the time zone from the callbacks received

void onLocationChanged(Location location)  

using the time information that can be obtained from the location parameter

long Time = location.getTime();

Or if there is another way please provide info!

A: 

You can use java.util.TimeZone to get information about the current time zone by calling TimeZone.getDefault(), like:

java.util.TimeZone tz = java.util.TimeZone.getDefault();
Toast.makeText(context, tz.getDisplayName(), Toast.LENGTH_LONG).show();
Thorstenvv
Correct but this returns the phone's time zone which might be incorrect , or inaccurate due to the fact that the user is traveling
rantravee
Alright, I misunderstood your intention then. Since the location times are always UTC I don't think there is a mechanism in place to support this. That would require some sort of geocode to time zone mapping, which exists in some GPS devices. Maybe a future feature for Android...
Thorstenvv
I think Android will automatically suggest to change the default timezone when roaming to another country.
Vitaly Polonetsky
Using the appropriate values ? Any idea how this is done ?
rantravee
+1  A: 

You can use web service provided by the geonames.org. Supply latitude and longitude to get the time zone information.

http://ws.geonames.org/timezoneJSON?lat=47.01&lng=10.2:

{"time":"2010-07-24 18:35","countryName":"Austria","sunset":"2010-07-24 21:02","rawOffset":1,"dstOffset":2,"countryCode":"AT","gmtOffset":1,"lng":10.2,"sunrise":"2010-07-24 05:48","timezoneId":"Europe/Vienna","lat":47.01}
CrazyCoder
That might work, but I want something that does not depend on an internet connection. Perhaps implementing the same algorithm for my application.
rantravee
That is possible, but you will need to distribute the database of countries, locations and time zones with your application. Also note that daylight saving information may change within 2 weeks.
CrazyCoder