我試圖訪問谷歌根據指導線在這裏映射時區API:https://developers.google.com/maps/documentation/timezone/intro訪問谷歌地圖時區API問題
如果我把網址:「https://maps.googleapis.com/maps/api/timezone/json?key=MY_API_KEY&location=43.7029682,-79.62146709999999×tamp=1500669556」在瀏覽器中,我可以得到預期的結果爲:
{
"dstOffset" : 3600,
"rawOffset" : -18000,
"status" : "OK",
"timeZoneId" : "America/Toronto",
"timeZoneName" : "Eastern Daylight Time"
}
然後,我試圖在angularJs中訪問此API。所以我用我平時用它來訪問其他API如下的方式:
var googleGeoTimeDefrred;
var getGoogleGeoTime = function(position) {
googleGeoTimeDefrred = $q.defer();
var userId = store.get("profile").user_id;
$http({
method:"GET",
url: "https://maps.googleapis.com/maps/api/timezone/json?key=MY_API_KEY&location=43.7029682,-79.62146709999999×tamp=1500669556"
}).then(function (success) {
googleGeoTimeDefrred.resolve(success);
}, function (error) {
googleGeoTimeDefrred.reject(status);
});
return googleGeoTimeDefrred.promise;
};
但我得到的錯誤:
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/timezone/json?key=MY_API_KEY&location=43.7029682,-79.62146709999999×tamp=1500669556. Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers in preflight response.
我是新來angularJs。我沒有問題使用上述方式訪問其他API(不是來自谷歌)。有誰知道是什麼原因導致這個問題?
謝謝。