Web Programming examples

Google Maps,AngularJS

Google Maps for AngularJS Simple Polylines(v2.0.7)

  • AngularJS : 1.2.23
  • Bootstrap : 3.2.0
  • Google Maps for AngularJS : 2.0.7
  • include file
  • angular.min.js, lodash.underscore.min.js, angular-google-maps.min.js, ui-bootstrap-tpls-0.11.0.min.js
<script type='text/javascript' src='http://www.example.com/wp/wp-content/themes/ang/js/lodash.underscore.min.js'></script>
<script type='text/javascript' src='http://www.example.com/wp/wp-content/themes/ang/js/angular-google-maps.min.js'></script>
<script type='text/javascript' src='http://www.example.com/wp/wp-content/themes/ang/js/app.js'></script>

<div ng-controller="MyCtrl">
<div class="row">
  <div class="col-sm-12">
    <ui-gmap-google-map 
      id="map-canvas"
      center="map.center"
      zoom="map.zoom"
      draggable="true"
      dragging="map.dragging"
      options="map.options"
    >
      <ui-gmap-polyline ng-repeat="p in map.polylines" 
                path="p.path"
                stroke="p.stroke" 
                visible='p.visible'
                geodesic='p.geodesic' 
                fit="false"
                editable="p.editable" 
                draggable="p.draggable">
      </ui-gmap-polyline>
    </ui-gmap-google-map>
  </div>
</div>
</div>
var mapApp = angular.module('googleMapApp', ['google-maps'.ns(),'ui.bootstrap']);
mapApp.config(['GoogleMapApiProvider'.ns(), function (GoogleMapApi) {
  GoogleMapApi.configure({
    key: 'your Google Map api key',
    v: '3.17',
    libraries: ''
  });
}]);

mapApp.controller("MyCtrl",['$scope', 'GoogleMapApi'.ns(), function ($scope,GoogleMapApi) {

  angular.extend($scope, {
  map: {
      center: {
        latitude: 35.681382,
        longitude: 139.766084
      },
      options: {
        maxZoom: 20,
        minZoom: 3
      },
      zoom: 15,
      polylines: [
          {
              path: [
                  {
                      latitude: 35.67941788049046,
                      longitude: 139.75768089294434
                  },
                  {
                      latitude: 35.67793632362604,
                      longitude: 139.76341009140015
                  },
                  {
                      latitude: 35.680759972963095,
                      longitude: 139.76446151733398
                  },
                  {
                      latitude: 35.68130028953324,
                      longitude: 139.76555585861206
                  }
              ],
              stroke: {
                  color: '#6060FB',
                  weight: 4
              },
              editable: true,
              draggable: false,
              geodesic: false,
              visible: true
          },
          {
              path: [
                  {
                      latitude: 35.682572633455436,
                      longitude: 139.77615594863892
                  },
                  {
                      latitude: 35.681579161170134,
                      longitude: 139.77576971054077
                  },
                  {
                      latitude: 35.682502916505676,
                      longitude: 139.77373123168945
                  },
                  {
                      latitude: 35.67920872118891,
                      longitude: 139.77173566818237
                  }
              ],
              stroke: {
                  color: '#6060FB',
                  weight: 3
              },
              editable: true,
              draggable: true,
              geodesic: true,
              visible: true
          }
      ]
  }
  });
}]);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.