【问题标题】:How to Take the correct time zone and location and date time from user如何从用户那里获取正确的时区、位置和日期时间
【发布时间】:2014-02-07 17:28:54
【问题描述】:

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

 // 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();

         }

我正在获取他的时区和日期时间以将它们添加到 url 中并从 inetrnet 获取一些信息,但如果用户有自动时区复选框,则未选中自动日期时间我会得到不正确的数据。那么我该如何解决这个问题呢? 您认为我应该在我的应用程序上将其作为注释提及还是我应该怎么做? 谢谢。

【问题讨论】:

    标签: android timezone android-location android-date


    【解决方案1】:

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

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

    【讨论】:

    • 嘿,非常感谢,但从我的阅读来看,我使用的似乎是最准确且成本最低的!正确的?或者你认为我应该使用什么?
    猜你喜欢
    • 2018-10-07
    • 1970-01-01
    • 2014-05-23
    • 2019-03-13
    • 2018-05-19
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 2015-07-29
    相关资源
    最近更新 更多