google-api - 哪些 Google 地方 API 查询结果允许存储在数据库中?

标签 google-api google-places-api

我正在探索 Google API,主要是 Places API。由于对 Google Places API 的请求数限制为 100,000,因此我正在寻找方法来最大限度地减少发送到 API 的请求数。我正在考虑使用数据库来存储以前收到的响应,因此将来我可以在不向 API 发出请求的情况下检索它们,并且仅在所需数据之前未存储在我的数据库中的情况下才会向 API 发出请求.

根据 Google API 使用条款,特别是 10.1.3 Restrictions against Copying or Data Export 部分,不允许无限期地存储数据,但是暂时缓存它是合法的:

You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation if you do so temporarily (and in no event for more than 30 calendar days), securely, and in a manner that does not permit use of the Content outside of the Service; and (ii) any content identifier or key that the Maps APIs Documentation specifically permits you to store. For example, you must not use the Content to create an independent database of "places" or other local listings information.



我发现这部分没有很好地解释。我可以将 API 接收到的任何数据存储在我的数据库中 30 天还是仅存储地点 ID?因为在其他一些上下文中,我读到只允许存储 ID。我是这样理解的:我可以无限期地存储地点 ID,但只能使用整个数据 30 天。

因为我只阅读了几天有关 Google API 的文章,所以我可能错过了一些使用条款,所以如果您能帮助我,我将非常感激。

任何关于如何最小化 API 调用次数的建议,或分享与使用这些 API 的实际项目相关的一些经验,我们将不胜感激。此外,如果您可以向我推荐一些可以提供类似功能的替代 API,那将非常有帮助。

先感谢您!

最佳答案

根据我使用 Google Places API 的经验,您的理解几乎是正确的。让我用自己的话解释一下这两个规定:

i) 无需预取或在您的应用程序外部重新分发,您最多可以将 API 结果缓存 30 天。

ii) 您可以在您的应用程序特定数据中使用地点 ID 或 key ,但不能使用其他任何内容(例如,如果您的应用允许用户“签到”地点,您可以存储他们在用户对象上的位置 ID 列表并根据 ID 根据需要查找地点,但您无法存储包含 Google 名称/详细信息的所有地点的列表)。

为了减少 API 调用次数并加速我的应用程序,我所做的是将附近的地方调用缓存在一个简单的键值缓存中,其中键是四舍五入到一定精度的经纬度对(以便在一定的半径将命中缓存),该值是整个 JSON 结果字符串。这是我的代码,它是在 Google 的 App Engine 上运行的 Java:

// Using 4 decimal places for rounding represents approximately 11 meters of precision
// http://gis.stackexchange.com/questions/8650/how-to-measure-the-accuracy-of-latitude-and-longitude
public static final int LAT_LONG_CACHE_PRECISION = 4;

public static final int CACHE_DURATION_SEC = 24 * 60 * 60; // one day in seconds

...

String cacheKey = "lat,lng:" + round(latitude) + "," + round(longitude);
asyncCache.put(cacheKey, dataJSON, Expiration.byDeltaSeconds(CACHE_DURATION_SEC), MemcacheService.SetPolicy.SET_ALWAYS);

...

private static double round(double value) {
    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(LAT_LONG_CACHE_PRECISION, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

至于替代 API,我建议您查看以下内容:

Yelp API - 提供谷歌缺乏的酒吧/餐厅数据

Facebook API - 如果您已经在使用 Facebook 的 SDK,则易于使用

Factual: Places Crosswalk - 聚合和标准化来自许多来源的地点数据,包括 Facebook 和 Yelp,但不包括谷歌

目前我只使用 Google Places API,但我计划稍后添加 Yelp 或 Factual 以改进最终用户的结果。

关于google-api - 哪些 Google 地方 API 查询结果允许存储在数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28242795/

相关文章:

curl - 使用cURL Google API从刷新 token 获取访问 token

python - 使用 Google Maps API 获取企业名称

ios - Google Places iOS - 应用程序太大

google-maps - 通过地址查找企业 "At this location"

android - 在 Android 应用程序中,将来自 Google API 的 client_secret.json 存储在哪里?

iOS Today 扩展 POST 请求到 Google Directions API

python - 使用 Google People API 的 REST people.get() 中的 userId 参数无效

ruby - 谷歌共享联系人 API

swift - 第一行 tableview 部分覆盖

android - 如何从适用于 Android 的 Google Places API 获取地点详细信息?