当前界限形成谷歌地图与ng-map

时间:2016-01-11 01:54:08

标签: angularjs google-maps ionic ng-map

我用这个:ngmap.github.io和离子框架。

我尝试像这个js代码一样获得当前位置:

google.maps.event.addListener(map, 'idle', function(){
    var bounds = map.getBounds();
 //returns an object with the NorthEast and SouthWest LatLng points of the bounds

});

如何将此代码转换为angularjs?

1 个答案:

答案 0 :(得分:1)

根据the documentation

NgMap.getMap().then(function(map) {...})用于获取地图实例。

示例



var app = angular.module('myapp', ['ngMap']);
app.controller('mapcntrl', function (NgMap, $scope) {

    NgMap.getMap().then(function (map) {
        console.log(map.getBounds().toString());
    });
});

<script src="https://maps.google.com/maps/api/js"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<div ng-app="myapp" ng-controller="mapcntrl">
    <ng-map center="[-26.1367035,124.2706638]" zoom="5"></ng-map>
</div>
&#13;
&#13;
&#13;