标签: google-api-timezone

如何将我的 Google Maps Time Zone API 密钥限制为 Android 应用程序?

是否可以将时区 API 密钥限制为 Android 应用程序?

通过定义包名称和 SHA-1 哈希值,可以将 Google Maps Android API 和 Google Places API 密钥限制为某些 Android 应用程序。

这对于 Maps and Places API 来说没有问题,但对 Time Zone API 使用完全相同的设置会不断返回“ REQUEST_DENIED”。将应用程序限制设置回“无”会导致查询成功,但我不想让我的 API 密钥不受保护。

我调用API的方式如下:

double lat = 51.1789;
double lon = -1.8262;
long time = 1523092938; 
String Api_key = "#API_KEY#";

String query = "https://maps.googleapis.com/maps/api/timezone/json?location="+String.format(Locale.ROOT, "%.4f",lat)+","+String.format(Locale.ROOT, "%.4f",lon)+"&timestamp="+time+"&key="+ Api_key;

protected JSONObject doInBackground(String... params) {
        HttpURLConnection connection = null;
        BufferedReader reader = null;

        try {
            URL url = new URL(query);
            connection = (HttpURLConnection) …
Run Code Online (Sandbox Code Playgroud)

android api-key google-cloud-console google-api-timezone

5
推荐指数
1
解决办法
396
查看次数