我尝试从 AngularJS 应用程序请求 Google Timezone API。
\n\n但是当我提出请求时,我在预检请求中收到此错误:
\n\nXMLHttpRequest cannot load https://maps.googleapis.com/maps/api/timezone/json?location=48.8709,2.3561×tamp=14912286400&key=MY_KEY. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.\n
Run Code Online (Sandbox Code Playgroud)\n\n\n\n我尝试通过设置标头来禁用预检请求Content-Type: \'text/plain\'
,但始终存在预检请求。
您认为上述错误是由预检请求引起的还是您认为我应该看看另一个方向?
\n\n提前致谢
\n\n编辑:我知道如何在我的服务器上启用 CORS,这不是重点。我想要的是从我的 AngularJS 应用程序访问 Google API,而不在我的服务器上创建 \xc3\xa0 WS(如果可能的话)。如果我别无选择,我就会这么做,但在这种情况下,我知道该怎么做。
\n\n回答:感谢@Sebas,我解决了window.fetch()
API 的问题。这在 IE 上不起作用,但这里有一个很棒的 polyfill: https: //github.com/github/fetch。\n我不知道这是否是解决我的问题的最佳选择,但它确实有效。
我希望在我的Android应用中使用Google时区API.在他们的使用限制中,他们如下所述.
使用Google时区API的每24小时限制为2,500.Maps for Business客户每24小时收到100,000个请求.
这个24小时的时间限制是我的Android应用程序的每个用户还是我的Android应用程序的整个用户?
我正在使用 fetch 来调用Google TimeZone。但是当我尝试将纬度/经度和时间戳作为正文参数传递时,出现错误。
错误:无法在“Window”上执行“fetch”:使用 GET/HEAD 方法的请求不能有正文
这是我的代码。Google 允许这样称呼吗?
const data = new FormData();
data.append('location', this.latitude.value + ',' + this.longitude.value);
data.append('timestamp', Math.floor(Date.now() / 1000).toString());
data.append('key', 'my google API key')
const timeZoneResult = await fetch('https://maps.googleapis.com/maps/api/timezone/json', {
method: 'GET',
headers: {},
body: data,
});
const timeZone = await timeZoneResult.json();
Run Code Online (Sandbox Code Playgroud)
这样,所有的内容都在 url 字符串中,工作正常!
是否存在某个城市/地点的邮政编码为“XXXX”并且属于 2 个或更多时区?
我不确定这个问题是否有效。但由于互联网上有关位置和时区的大量信息,我有点困惑。
(我的要求实际上是将用户的国家、城市、邮政编码和时区信息存储在数据库中)
database timezone geolocation postal-code google-maps-timezone
javascript ×2
android ×1
angularjs ×1
cors ×1
database ×1
fetch ×1
geolocation ×1
google-maps ×1
postal-code ×1
preflight ×1
timezone ×1