2016-05-21 9 views
0

Googleマップ(特に場所)を使用しているAngularJSを使用してChrome拡張機能を構築しています。Angularを使用してChrome拡張機能でGoogle Mapsスクリプトを読み込むにはどうすればよいですか?

私はそれがChromeの拡張機能ではありません場合は正常に動作します上記

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 
    <style type="text/css"> 
     body 
     { 
      font-family: Arial; 
      font-size: 10pt; 
     } 
    </style> 
</head> 
<body> 
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script> 
    <script type="text/javascript"> 
     google.maps.event.addDomListener(window, 'load', function() { 
      var places = new google.maps.places.Autocomplete(document.getElementById('txtPlaces')); 
      google.maps.event.addListener(places, 'place_changed', function() { 
       var place = places.getPlace(); 
       var address = place.formatted_address; 
       var latitude = place.geometry.location.lat(); 
       var longitude = place.geometry.location.lng(); 
       var mesg = "Address: " + address; 
       mesg += "\nLatitude: " + latitude; 
       mesg += "\nLongitude: " + longitude; 
       alert(mesg); 
      }); 
     }); 
    </script> 
    <span>Location:</span> 
    <input type="text" id="txtPlaces" style="width: 250px" placeholder="Enter a location" /> 
</body> 
</html> 

と同様の機能を探しています。しかし、私はGoogleマップスクリプト

http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places 

をロードしようとしたとき、私は私が

"content_security_policy": "script-src 'self' https://maps.googleapis.com https://ssl.google-analytics.com; object-src 'self'", 
にマニフェストを変更するとエラーが

Refused to load the script 'http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places' because it violates the following Content Security Policy directive: "script-src 'self' https://ssl.google-analytics.com". 

を言ってもらうChromeの拡張機能を構築していますので、

私はまだ同じ 'スクリプトを読み込むのが拒否されました'というエラーが表示されます。

私の質問は、HTMLファイルに直接ロードせずにGoogle Mapsライブラリをロードするにはどうすればよいですか?

+0

https://maps.googleapis.com/maps/api/js?sensor = false&libraries = places'を試してください –

+0

httpsを使用しても同じエラーが表示されます – sharataka

答えて

0

By defaultインラインスクリプトは実行されず、ローカルスクリプトのみが読み込まれます。

content_securiy_policyフィールドにリモートURL(httpsで始まる)を追加するだけでなく、インラインスクリプトを外部ファイルに抽出して含める必要があります。

0

マニフェストにhttps://maps.googleapis.comを追加することができました。私はファイルをクロムにリロードしていなかったので、以前は動作していませんでした。私はリロードされたので、それは動作しています!

関連する問題