我想创建一个工厂,使用 $resource 从谷歌的距离 api ( https://developers.google.com/maps/documentation/distancematrix/ ) 检索距离信息。
我已经剥离了参数以尝试让简单的服务正常工作..
这是我当前的代码:
VenuesAppServices.factory('VenueDistance', ['$resource',
function($resource){
return $resource('http://maps.googleapis.com/maps/api/distancematrix/json', {}, {
Distance: {method:'GET'}
});
}]);
并称之为:
VenueDistance.Distance(function(results){
alert(JSON.stringify(results));
},function(error){
alert(JSON.stringify(error));
});
我希望返回以下内容:
{
"destination_addresses" : [],
"error_message" : "The 'sensor' parameter specified in the request must be set to either 'true' or 'false'.",
"origin_addresses" : [],
"rows" : [],
"status" : "REQUEST_DENIED"
}
但是我得到了 404 响应。
{"data":"","status":404,"config":{"transformRequest":[null],"transformResponse":[null],"method":"GET","url":"http://maps.googleapis.com/maps/api/distancematrix/json","headers":{"Accept":"application/json, text/plain, */*"}}}
如果您将 google api 换成类似 ( http://api.geonames.org/postalCodeLookupJSON )。然后,您会从该站点获得预期的响应。
谁能告诉我为什么 google url 没有返回您从浏览器获得的结果?