0

I am using this code to detect the location of the user:

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

         }

and I am getting his time zone and datetime to add these in a url and get some info from the inetrnet but if the user has the checkboxes of automatic timezone, automatic date time unchecked I get incorrect data. So how can I fix this? Do you think that I should mention this as a note on my app or what should I do? thanks.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Learning Android
  • 273
  • 4
  • 17

1 Answers1

1

You can call out to a web service with the latitude and longitude to retrieve the time zone.

See: How to get a time zone from a location.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • hey thank you very much but from what I've read it seems that the one that I've used is the most accurate and the one with low cost!! right? or what do you think I should use? – Learning Android Jan 18 '14 at 11:51