- 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
{{ title }}
latitude,longitude {{ latitude | number:4 }}, {{ longitude | number:4 }}
<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'" click="'onClicked'" >
<ui-gmap-windows show="'showWindow'" closeClick="'closeClick'">
<p ng-non-bindable><strong>{{ title }}</strong><br />
latitude,longitude {{ latitude | number:4 }}, {{ longitude | number:4 }}
</p>
</ui-gmap-windows>
</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: {
maxZoom: 20,
minZoom: 3
},
zoom: 16,
markers: [
{
latitude: 35.681382,
longitude: 139.766084,
showWindow: false,
title: 'Tokyo Station',
id:1
},
{
latitude: 35.682032,
longitude: 139.762294,
showWindow: false,
title: 'wadakuramon',
id: 2
},
{
latitude: 35.678354,
longitude: 139.761028,
showWindow: false,
title: 'babasakimon',
id:3
}
]
}
});
angular.forEach($scope.map.markers, function (marker) {
marker.closeClick = function () {
marker.showWindow = false;
$scope.$apply();
};
marker.onClicked = function () {
marker.showWindow = true;
$scope.$apply();
};
});
uiGmapGoogleMapApi.then(function(maps) {});
}]);