2014-08-28 53 views
0

我一直在努力提出一個簡單的GET請求,谷歌Places API的離子應用程序無法提交GET請求

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=xxxx

我不斷收到錯誤: 的XMLHttpRequest無法加載https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8 ... IUS = 500 & types =食物& name = cruise & key = xxxx。請求的資源上沒有「Access-Control-Allow-Origin」標題。因此不允許原產地'8100'進入。

我在網上查了一下,它與CORS有關,但我還沒有弄清楚什麼。如果有人能指出我會朝着正確的方向發展,那將是很棒的。

謝謝

回答

0

我能夠使用離子平穩地調用該網址。

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" /> 
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
    <link href="components/lib/ionic/css/ionic.css" rel="stylesheet" /> 
    <script src="components/lib/ionic/js/ionic.bundle.js"></script> 
    <script src="components/lib/ionic/js/angular/angular-resource.js"></script> 
    <script type="text/javascript"> 
     angular.module('myApp', 
[ 
'ionic', 
'ngResource' 
]) 
.factory('GetData', function ($resource) 
{ 
    return { 
     getg: function() 
     { 
      return $resource('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=xxxx', null).get(); 
     } 
    } 
}) 
.controller('SomeController', function (GetData) 
{ 
    GetData.getg().$promise.then(
     function (answer) 
     { 
      console.log(answer); 
     }); 
}); 
    </script> 
</head> 
    <body ng-app="myApp" ng-controller="SomeController"></body> 
</html> 
+0

嗯那怪異的進出口仍然得到同樣的錯誤。這裏是codepen http://codepen.io/anon/pen/hLimd?editors=101 – user3716926 2014-08-29 20:50:26

0

什麼工作對我來說是安裝這個插件:

  • 科爾多瓦 - 插件白名單

Console:

cordova plugin add cordova-plugin-whitelist