Polymer-google-map

提供:Dev Guides
移動先:案内検索

ポリマー-Googleマップ

<google-map>は、Googleマップを表示するために使用される要素です。

<google-map latitude = "17.77591" longitude = "-524.41144" api-key = "4586"></google-map>

startAddressとendAddressの間の地図の方向を表示するには、次のコードに示すようにgooglemap-directionsを使用できます-

<google-map-directions map="[[map]]"
   start-address = "United States" end-address = "Mountain View">
</google-map-directions>

google-map要素を使用するには、コマンドプロンプトでプロジェクトフォルダに移動し、次のコマンドを使用します-

bower install PolymerElements/google-map --save

上記のコマンドは、bower_componentsフォルダーにgoogle-map要素をインストールします。 次に、次のコマンドを使用して、Googleマップファイルをインデックスにインポートします。

<link rel = "import" href = "/bower_components/google-map/google-mapl">

次の例は、google-map要素の使用方法を示しています。

<!DOCTYPE html>
<html>
   <head>
      <title>google-map</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <script src = "bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
      <link rel = "import"
         href = "https://rawgit.com/Download/polymer-cdn/master/lib/google-map/google-mapl">

      <style>
         google-map {
            height: 250px;
            width: 380px;
            border: 2px solid black;
            margin: 25px 20px 20px 20px;
         }
      </style>
   </head>

   <body>
      <h2>Google-Map Example</h2>
      <demo-map></demo-map>
      <dom-module id = "demo-map">
         <template>
            <google-map map = "{{map}}" latitude = "37.779" longitude = "-122.3892">
            </google-map>
         </template>
      </dom-module>

      <script>
         Polymer ({
            is: "demo-map", properties: {
               Address: {
                  type: String, value: "San Francisco"
               }, map: "demo-map"
            }
         });
      </script>
  </body>
</html>

出力

アプリケーションを実行するには、プロジェクトディレクトリに移動し、次のコマンドを実行します。

polymer serve

ここでブラウザを開き、 http://127.0.0.1:8081/ に移動します。 出力は次のようになります。

Google Map