$resource を使用してファクトリを作成し、Google の距離 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 がブラウザから取得した結果を返さない理由を誰か教えてもらえますか?