Skip to content

Instantly share code, notes, and snippets.

@hideack
Created August 30, 2020 00:59
Show Gist options
  • Select an option

  • Save hideack/47d4389fe1ea51474dfda0c2870ce2df to your computer and use it in GitHub Desktop.

Select an option

Save hideack/47d4389fe1ea51474dfda0c2870ce2df to your computer and use it in GitHub Desktop.
ip-api.com を利用した所在地取得
function getRegionName(ip) {
var cache = CacheService.getPublicCache();
var cacheKey = "api:ip-api.com:" + ip;
var region = cache.get(cacheKey);
if (region == null) {
var geo = UrlFetchApp.fetch("http://ip-api.com/json/" + ip).getContentText();
region = JSON.parse(geo).regionName;
cache.put(cacheKey, region, 60 * 60 * 8);
}
return region;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment