我正在使用Google API和XMLHTTPRequest来检索地址信息,而不会出现任何问题。
xhr.open("POST", "http://maps.googleapis.com/maps/api/geocode/json?"+ data +"&sensor=true", true);
但是当我尝试使用distancematrix检索信息时出现以下错误:
xhr.open("POST", "http://maps.googleapis.com/maps/api/distancematrix/json?origins="+data.lat1+","+data.lng1+"&destinations="+data.lat2+","+data.lng2+"&mode=driving&language=pl-PL", true);
XMLHttpRequest cannot load http://maps.googleapis.com/maps/api/distancematrix/json?origins=46.4576003,…4169999999&destinations=51.2769239,-114.021174&mode=driving&language=pl-PL. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
知道为什么会这样吗?