如何从用户那里获取正确的时区,位置和日期时间

时间:2014-01-18 08:36:05

标签: android timezone android-location android-date

我正在使用此代码来检测用户的位置:

 // Acquire a reference to the system Location Manager
         locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

         // Define a listener that responds to location updates
         locationListener = new LocationListener() {
             public void onLocationChanged(Location location) {
               // Called when a new location is found by the network location provider.
               longitude=location.getLongitude();
               latitude=location.getLatitude();

             }


             public void onStatusChanged(String provider, int status, Bundle extras) {}

             public void onProviderEnabled(String provider) {}

             public void onProviderDisabled(String provider) {}
           };

         //Or use LocationManager.GPS_PROVIDER
         String locationProvider = LocationManager.NETWORK_PROVIDER;

         // Register the listener with the Location Manager to receive location updates
         locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);

         Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);

         if(lastKnownLocation!=null){
             longitude=lastKnownLocation.getLongitude();
             latitude=lastKnownLocation.getLatitude();

         }

我正在将他的时区和日期时间添加到网址并从inetrnet获取一些信息,但如果用户有自动时区的复选框,则自动日期时间未选中,我得到的数据不正确。那么我该如何解决这个问题呢? 你认为我应该在我的应用程序上注明这个或者我应该怎么做? 感谢。

1 个答案:

答案 0 :(得分:1)

您可以呼叫具有纬度和经度的网络服务来检索时区。

请参阅:How to get a time zone from a location