0

I am getting current latitude and longitude in map box, I need current timezone based on current latitude and longitude.

For example.My device time is the USA but my location showing in India so I need India timezone.Can you please help me.

@Override
    public void onLocationChanged(Location location) {
        try {
            mLatLng = new LatLng(location.getLatitude(), location.getLongitude());
            Log.i("EE","mLatLngmLatLng"+mLatLng);
            String time = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SSS").format(location.getTime());

            Log.i("EE","time----"+time);
            Log.i("EE","vlocation.getTime()----"+location.getTime());

            updateCamera();
            if (mMarker != null) {
                updateMarker();
            }else{
                addMarker();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
kalai vani
  • 289
  • 2
  • 4
  • 21

1 Answers1

0

Get address by Geocoder and identify country, When you will get the country name It will be easy for you to identify the time Zone.

  private void getAddressFromLocation(double latitude, double longitude) {

    Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);


    try {
        List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);

        if (addresses.size() > 0) {
            Address fetchedAddress = addresses.get(0);
            StringBuilder strAddress = new StringBuilder();
            for (int i = 0; i < fetchedAddress.getMaxAddressLineIndex(); i++) {
                strAddress.append(fetchedAddress.getAddressLine(i)).append(" ");
            }

            txtLocationAddress.setText(strAddress.toString());

        } else {
            txtLocationAddress.setText("Searching Current Address");
        }

    } catch (IOException e) {
        e.printStackTrace();
        printToast("Could not get address..!");
    }
}
Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
  • Hi Abhishek,USA country have many timezone ,how to find particular timezone for lat and long – kalai vani Jan 23 '18 at 09:53
  • can yo checked this https://stackoverflow.com/questions/45767424/get-timezone-by-lat-and-long-in-android @kalaivani – Abhishek kumar Jan 23 '18 at 09:58
  • I checked , but there is no solution.they given like this double zone = (responseObject.get("rawOffset").getAsInt() + responseObject.get("dstOffset").getAsInt()) / 3600.0;.I dont rawoffset value – kalai vani Jan 23 '18 at 10:15