【问题标题】:Angular and google distance matrix no access control header角度和谷歌距离矩阵没有访问控制标题
【发布时间】:2017-09-24 20:57:25
【问题描述】:

我来了

XMLHttpRequest 无法加载 https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=bl79yt&destinations=cw73bz&key=mykey。 请求中不存在“Access-Control-Allow-Origin”标头 资源。

在我的 Angular 应用程序中。我对谷歌距离矩阵有我的 http 请求,如下所示:

 var url = 'https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=' + pcodefrom + '&destinations=' + pcodeto + '&key=mykeyhere';
  console.log(url);
     $http({method: 'GET', url: url,headers: {
            "X-Content-Type-Options": "nosniff",
            "X-Frame-Options": "SAMEORIGIN",
            "X-Rack-CORS": "preflight-hit; no-origin"
        }}).success(function(data) {
            };
                    }).error(function(data){

                    });

我已经在 google api 控制台中允许了网站 url,但它仍然无法正常工作。

【问题讨论】:

    标签: angularjs google-maps google-maps-api-3


    【解决方案1】:

    您无能为力,因为 CORS 标头应在 Google 后端服务器上设置。

    为避免 CORS 问题,您应该使用 Google Maps JavaScript API 的距离矩阵服务:

    https://developers.google.com/maps/documentation/javascript/distancematrix

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多