1

我使用这个:ngmap.github.io 和 ionic 框架。

我尝试像这个 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?

4

1 回答 1

1

根据文档

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>

于 2016-01-20T14:03:24.123 回答