Web Programming examples

Google Maps,AngularJS

Google Maps for AngularJS Street View simple(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-6">
    <ui-gmap-google-map 
      id="map-canvas"
      center="map.center"
      zoom="map.zoom"
      draggable="true"
      options="map.options"
      control="map.control"
      events="map.events"
    >
    </ui-gmap-google-map>
  </div>
  <div class="col-sm-6">
  <div id="pano" style=" height: 400px;"></div>
  </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.765084
      },
      options: {
        maxZoom: 20,
        minZoom: 3
      },
      zoom: 15,
      control: {},
      events: {
        projection_changed: function (map, eventName, originalEventArgs) {
          var Tokyo = new google.maps.LatLng($scope.map.center.latitude, $scope.map.center.longitude);
          var panoramaOptions = {
            position: Tokyo,
            pov: {
              heading: 30,
              pitch: 5,
              zoom: 2
            }
          };
          var panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'),panoramaOptions);
          map.setStreetView(panorama);
        }
      }
    }
  });
}]);

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.