Web Programming examples

Google Maps,AngularJS

Google Maps for AngularJS markers-label(v2.4.1)

  • AngularJS : 1.6.5
  • Google Maps for AngularJS : 2.4.1
  • include file
  • angular.min.js, lodash.underscore.min.js, angular-simple-logger.min.js,angular-google-maps.min.js

<script type='text/javascript' src='https://unpkg.com/lodash@4.0.1/lodash.js'></script>
<script type='text/javascript' src='http://www.example.com/wp/wp-content/themes/ang/js/angular.min.js'></script>
<script type='text/javascript' src='https://unpkg.com/angular-simple-logger@0.1.7/dist/angular-simple-logger.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" options="map.options">
        <ui-gmap-markers models="map.markers" coords="'self'"
          options="'options'" icon="'icon'" isLabel='true' >
        </ui-gmap-markers>
      </ui-gmap-google-map>
    </div>
  </div>
</div>

var mapApp = angular.module('googleMapApp', ['uiGmapgoogle-maps']);

mapApp.config(
    ['uiGmapGoogleMapApiProvider', function(GoogleMapApiProviders) {
        GoogleMapApiProviders.configure({
          key: 'your Google Map api key',
          v: '3', //defaults to latest 3.X anyhow
          libraries: 'weather,geometry,visualization'
        });
    }]
);

mapApp.controller("MyCtrl",['$scope', 'uiGmapGoogleMapApi', function ($scope,uiGmapGoogleMapApi) {
  angular.extend($scope, {
    map: {
      center: {
        latitude: 35.681382,
        longitude: 139.766084
      },
      options: {},
      zoom: 15,
      markers: [
        {
          latitude: 35.681382,
          longitude: 139.766084,
          icon: 'http://maps.google.co.jp/mapfiles/ms/icons/pink.png',
          id: 1,
          options: {
            labelContent: 1,
            labelAnchor: '4 30',
            labelClass: 'marker-labels1'
          },
        },
        {
          latitude: 35.682032,
          longitude: 139.762294,
          icon: 'http://maps.google.co.jp/mapfiles/ms/icons/pink.png',
          id: 2,
          options: {
            labelContent: 2,
            labelAnchor: '4 30',
            labelClass: 'marker-labels1'
          },
        },
        {
          latitude: 35.678354,
          longitude: 139.761028,
          icon: 'http://maps.google.co.jp/mapfiles/ms/icons/pink.png',
          id: 3,
          options: {
            labelContent: 3,
            labelAnchor: '4 30',
            labelClass: 'marker-labels1'
          },
        }
      ]
    }
  });
  uiGmapGoogleMapApi.then(function(maps) {});
}]);