zee*_*ari 5 java google-app-engine app-engine-flexible
根据Google App Engine灵活的文档,对于任何传入请求,作为应用程序的服务,App Engine会向所有请求添加以下标头:
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]
Run Code Online (Sandbox Code Playgroud)
无论如何,我可以使用Java从请求标头使用上述信息获得时区偏移量?
添加以下内容到pom.xml
<dependency>
<groupId>net.iakovlev</groupId>
<artifactId>timeshape</artifactId>
<version>2018d.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
然后运行下面的代码类型
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;
}
}
Run Code Online (Sandbox Code Playgroud)
结果是
Optional[Asia/Kolkata]
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方式获取当前坐标
https://mylocationtest.appspot.com/