我用这个: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?
答案 0 :(得分: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>
&#13;