Web Programming examples

Google Maps,AngularJS

Google Maps for AngularJS Street View data(v2.4.1)

  • AngularJS : 1.5.9
  • 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
Click on map.
<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-marker coords="map.marker" idKey="map.marker.id" 
               options="map.marker.options" isLabel='true'>
      </ui-gmap-marker>
    </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', ['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) {
  var panorama;
  angular.extend($scope, {
    map: {
      center: {
        latitude: 35.681382,
        longitude: 139.766084
      },
      options: {
        maxZoom: 20,
        minZoom: 3
      },
      zoom: 15,
      control: {},
      events: {
        click: function (map, eventName, originalEventArgs) {
          var sv = new google.maps.StreetViewService();
          var event = originalEventArgs[0];
          sv.getPanoramaByLocation(event.latLng, 50, processSVData);
        }
      },
      marker: {
        id: 1,
        options: {}
      }
    }
  });

  function processSVData(data, status) {
    if (status == google.maps.StreetViewStatus.OK) {
      $scope.map.marker.latitude = data.location.latLng.lat();
      $scope.map.marker.longitude = data.location.latLng.lng();
      $scope.map.marker.id = 1;
      $scope.map.marker.options.labelContent = data.location.description;
      $scope.map.marker.options.labelAnchor = '0 30';
      panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'));
      panorama.setPano(data.location.pano);
      panorama.setPov({
        heading: 270,
        pitch: 0
      });
      panorama.setVisible(true);
      $scope.$apply();
    } else {
      alert('Street View data not found for this location.');
    }
  }
  uiGmapGoogleMapApi.then(function(maps) {});
}]);