ngmap
Version:
The Simplest AngularJS Google Maps V3 Directive
71 lines (52 loc) • 1.82 kB
HTML
<html>
<head>
<title>Place Autocomplete Address Form</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="script-tags-for-development.js"></script>
<script>
angular.module('myApp', ['ngMap']).controller('MyCtrl', function($scope, NgMap) {
var vm = this;
vm.types = "['establishment']";
vm.mybounds = {south_west: {lat: 36, lng: 6}, north_east: {lat: 47, lng: 18}};
vm.placeChanged = function() {
vm.place = this.getPlace();
console.log('location', vm.place.geometry.location);
vm.map.setCenter(vm.place.geometry.location);
}
NgMap.getMap().then(function(map) {
vm.map = map;
});
});
</script>
</head>
<body ng-app="myApp" ng-controller="MyCtrl as vm">
Auto Complete Type:
<select ng-model="vm.types">
<option value="['geocode']">Geodode</option>
<option value="['establishment']">Establishment</option>
<option value="['address']">Address</option>
</select><br/>
Bounds Lat: <input type="number" ng-model="vm.mybounds.south_west.lat" style="width: 40px;"></input>
Lng: <input type="number" ng-model="vm.mybounds.south_west.lng" style="width: 40px;"></input>
Lat: <input type="number" ng-model="vm.mybounds.north_east.lat" style="width: 40px;"></input>
Lng: <input type="number" ng-model="vm.mybounds.north_east.lng" style="width: 40px;"></input>
<br/>
<br/>
Enter an address: <br/>
<input places-auto-complete
size=80
ng-model="vm.address"
strict-bounds="true"
rect-bounds="{{vm.mybounds}}"
types="{{types}}"
on-place-changed="vm.placeChanged()" /> <br/>
<div ng-show="vm.place">
Address = {{vm.place.formatted_address}} <br/>
Location: {{vm.place.geometry.location}}<br/>
</div>
address : {{vm.address}}
<br/>
<ng-map></ng-map>
</body>
</html>