Polymer - Google Map



The <google-map> is an element used to display a google map.

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

To show the map directions between a startAddress and endAddress, you can use googlemap-directions as shown in the following code −

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

Example

To use the google-map element, navigate to your project folder in the command prompt and use the following command −

bower install PolymerElements/google-map --save

The above command installs the google-map element in bower_components folder. Next, import the google-map file in your index.html using the following command.

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

The following example demonstrates the use of google-map element.

<!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>

Output

To run the application, navigate to your project directory and run the following command.

polymer serve

Now open the browser and navigate to http://127.0.0.1:8081/. Following will be the output.

Google Map
polymer_elements.htm
Advertisements