public static String TimezoneUrl = "https://maps.googleapis.com/maps/api/timezone/json?";
API_KEY="Your API service key";
newurl = TimezoneUrl+"location="+myLatitude+","
+myLongitude+"×tamp="+System.currentTimeMillis()/1000 + "&key=" + API_KEY;
response = makeServiceCall(url, ServiceHandler.GET);
jsonResponse = new JSONObject(response);
timesone = jsonResponse.getString("timeZoneName");
for (int i = 0; i < timesone.length(); i++) {
if (Character.isUpperCase(timesone.charAt(i))) {
char c = timesone.charAt(i);
timezone = timezone + c;
}
}
public String makeServiceCall(String url, int method) {
return this.makeServiceCall(url, method, null);
}
public String makeServiceCall(String url, int method,
List<NameValuePair> params) {
try {
// http client
DefaultHttpClient httpClient = new DefaultHttpClient();
//httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Custom user agent");
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
// Checking http request method type
if (method == GET) {
// appending params to url
if (params != null) {
String paramString = URLEncodedUtils .format(params, "utf-8");
url += "?" + paramString;
}
HttpGet httpGet = new HttpGet(url);
httpResponse = httpClient.execute(httpGet);
}
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
結果會給你IST像您期望的時區。
請嘗試https://developers.google.com/maps/documentation/timezone/ – jenuine 2014-12-11 06:14:25