As per Google App Engine flexible docs, for any incoming request, as a service to the app, App Engine adds the following headers to all requests:
X-AppEngine-Country as an ISO 3166-1 alpha-2 country code
X-AppEngine-Region as an ISO-3166-2 standard
X-AppEngine-City
X-AppEngine-CityLatLong
X-Cloud-Trace-Context
X-Forwarded-For: [CLIENT_IP(s)], [global forwarding rule IP]
X-Forwarded-Proto [http | https]
Is there anyway I can get timezone offset using above info from request header using Java?
To learn more, see Get Started with Google Maps Platform. The Time Zone API provides time offset data for locations on the surface of the earth. Request the time zone information for a specific latitude/longitude pair and date. The API returns the name of that time zone, the time offset from UTC, and the daylight savings offset.
As a service to the app, App Engine adds the following headers to all requests: Country from which the request originated, as an ISO 3166-1 alpha-2 country code. App Engine determines this code from the client's IP address.
The Time Zone API Developer Guide is intended for website and mobile developers who want to include time data on maps provided by one of the Google Maps Platform APIs. It provides an introduction to using the API and reference material on the available parameters.
Also, the Content-Encoding request header is not checked by the server, so if the client sends a gzipped request body, it will be sent in compressed form to the application. As a service to the app, App Engine adds the following headers to all requests:
Add below to the pom.xml
<dependency>
<groupId>net.iakovlev</groupId>
<artifactId>timeshape</artifactId>
<version>2018d.1</version>
</dependency>
And then run below type of code
package taruntest;
import net.iakovlev.timeshape.TimeZoneEngine;
import java.time.ZoneId;
import java.util.Optional;
public class ZoneInfo {
public static TimeZoneEngine engine = null;
private static Optional<ZoneId> ZoneID;
public static void main(String[] args) {
ZoneID = getZoneIdFromLatLong("12.971599,77.594563");
System.out.println(ZoneID.toString());
}
public static Optional<ZoneId> getZoneIdFromLatLong(String latLong) {
if (engine == null)
{
engine = TimeZoneEngine.initialize();
}
String[] latLongArr = latLong.split(",");
double _lat = Double.parseDouble(latLongArr[0]);
double _long = Double.parseDouble(latLongArr[1]);
Optional<ZoneId> maybeZoneId = engine.query(_lat, _long);
return maybeZoneId;
}
}
The result is
Optional[Asia/Kolkata]
You can get your current coords using
https://mylocationtest.appspot.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With