角和谷歌距离矩阵没有访问控制标头 [英] Angular and google distance matrix no access control header

查看:102
本文介绍了角和谷歌距离矩阵没有访问控制标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要

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

XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=bl79yt&destinations=cw73bz&key=mykey. No 'Access-Control-Allow-Origin' header is present on the requested resource.

在我的角度应用程序中.我对Google距离矩阵有这样的http请求:

In my angular app. I have my http request to the google distance matrix like this :

 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控制台中的网站网址,但是仍然无法正常工作.

Ive allowed the website url in the google api console but it's still not working.

推荐答案

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

There is nothing you can do because the CORS headers should be set on Google backend servers.

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

To avoid CORS issues you should use the distance matrix service of Google Maps JavaScript API:

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

这篇关于角和谷歌距离矩阵没有访问控制标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆