Android 如何从用户处获取正确的时区、位置和日期时间
我正在使用此代码检测用户的位置:Android 如何从用户处获取正确的时区、位置和日期时间,android,timezone,android-location,android-date,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 locationLi
// 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中,并从iNet获取一些信息,但是如果用户有自动时区、自动日期时间复选框未选中,我会得到不正确的数据。那么我该如何解决这个问题呢?
你认为我应该在我的应用程序上记下这个,或者我应该怎么做?
谢谢。您可以调用带有纬度和经度的web服务来检索时区
请参阅:。嘿,非常感谢,但从我的阅读来看,我使用的是最准确、成本最低的!!正确的?或者你认为我应该用什么?