Polymer - Google Map

<google-map> 是用于显示谷歌地图的元素。

<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 元素。接下来,使用以下命令在 index.html 中导入 google-map 文件。

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

以下示例演示了 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-map.html">

      <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

polymer_elements.html