ngmap
Version:
The Simplest AngularJS Google Maps V3 Directive
31 lines (28 loc) • 872 B
HTML
<html ng-app="myapp">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="script-tags-for-development.js"></script>
<script>
var app = angular.module('myapp', ['ngMap']);
app.controller('MyCtrl', function(NgMap) {
var vm = this;
vm.positions = [ [-24,132] ,[-25,131] ,[-26,130] ];
var bounds = new google.maps.LatLngBounds();
for (var i=0; i<vm.positions.length; i++) {
var latlng = new google.maps.LatLng(vm.positions[i][0], vm.positions[i][1]);
bounds.extend(latlng);
}
NgMap.getMap().then(function(map) {
map.setCenter(bounds.getCenter());
map.fitBounds(bounds);
});
});
</script>
</head>
<body ng-controller="MyCtrl as vm">
<ng-map center="-25,131">
<marker ng-repeat="pos in vm.positions" position="{{pos}}"></marker>
</ng-map>
</body>
</html>