1

I am using ngMap and specifically this example: https://ngmap.github.io/#/!shape_circle_with_current_position.html

It lets the user draw a circle and specify its radius.

How do I retrieve the center coordinate and the radius size?

This is my controller:

angular.module('myApp')
    .controller('someCtrl', function ($scope, NgMap, someService) {     

    NgMap.getMap().then(function(map) {
    });   

    $scope.someMethod = someMethod;

    function someMethod () {
        someService.addLocation(lat, lon, radius);
    }
});

I couldn't find any example.

Cœur
  • 37,241
  • 25
  • 195
  • 267
HideAndSeek
  • 374
  • 3
  • 16

1 Answers1

1

You can get the instance of the circle from NgMap service which is used to retrieve the map object using deferred promise. From that circle object , you can get the radius & center coordinates. Suppose if the id of your shape is circle . Then below snippet will retrieve the center & radius.

angular.module('myApp')
    .controller('someCtrl', function ($scope, NgMap, someService) {     

      NgMap.getMap().then(function(map) {
          console.log("Radius of the circle : " + map.shapes.circle.radius);
          console.log("Center's Latitude : " + map.shapes.circle.center.lat());
          console.log("Center's Langitude : " + map.shapes.circle.center.lng());
      });   

      $scope.someMethod = someMethod;

      function someMethod () {
         someService.addLocation(lat, lon, radius);
      }
   });
Sasank Sunkavalli
  • 3,864
  • 5
  • 31
  • 55