angular-ui / angular-google-maps

AngularJS directives for the Google Maps Javascript API
http://angular-ui.github.io/angular-google-maps
2.52k stars 1.07k forks source link

Uncaught TypeError: $scope.map.control.getGMap is not a function when click on Map #1736

Open neelabhsingh opened 8 years ago

neelabhsingh commented 8 years ago

I am working on Angular-Google-MAP. I want to added marker to map. But when I click on Map, I am getting error $scope.map.control.getGMap is not a function. This is defined in geocodePosition(), when Map click even called. Please let me know why it is not working....

<ui-gmap-google-map center='map.center' zoom='map.zoom' control='map.control' id="map-canvas" events="map.events">
   <ui-gmap-markers models="markers" idkey="markers.id" coords="'coords'"  events="markerEvents" icon="'icon'">                 
   </ui-gmap-markers>   
</ui-gmap-google-map>

In controller

 function MapController($scope, GMapReady, GoogleMapApi, $timeout) {
     GMapReady.promise().then(
         var map={
             center: {
               latitude: 21.1458004,
               longitude: 79.08815460000005
             },
             bounds : {northeast : { latitude : 79.08815460000005, longitude : 79.08815460000005},
                       southwest : { latitude : 79.08815460000005, longitude : 79.08815460000005}},
             zoom: 5,
             control : {}
            }; 
            $scope.map=map;

            $scope.map.events ={
               click: function(map, eventName, originalEventArgs){

              var e=originalEventArgs[0];
              var lat=e.latLng.lat(),lon=e.latLng.lng();

              var latlng = new google.maps.LatLng(lat, lon);
              geocodePosition(latlng);                 
            }
        }// end of Map event
     );

    function geocodePosition(pos){
       .....some code .......
       ......................
     var map_obj=$scope.map.control.getGMap();
     var service = new google.maps.places.PlacesService(map_obj);  
    };
 }
nmccready commented 8 years ago

Please make me a reproducible example.