Updating maps and markers with angular -google-maps

Hey. I am using angular -google-maps for my project. The html and js code is as follows

HTML:
   

        <ui-gmap-markers models="apartments" coords="'loc'" icon="'assets/images/map_icon_normal.png'" idkey="'_id'"
                     fit="'false'" click="click">


      <ui-gmap-windows show="'show'" >
        <div ng-non-bindable>{{streetAddress}}</div>

      </ui-gmap-windows>
    </ui-gmap-markers>



  </ui-gmap-google-map>

Script: angular.module ('MYAPP')

.controller('MapCtrl',
                    function ($scope, $routeParams, Map, uiGmapGoogleMapApi) {
 $scope.apartments = [];
 $scope.customIcon = "../../assets/images/map_icon_normal.png"

$scope.map = {
      center: {
        latitude: $routeParams.lat,
        longitude: $routeParams.lon
      },

      zoom: 5,
      bounds: {},
      events: {
        tilesloaded: function (map) {
          //console.log('tiles loaded');
          $scope.$apply(function () {
            $scope.mapInstance = map;
            //console.log(map.getBounds().getNorthEast());
            $scope.searchbox.options.bounds = new google.maps.LatLngBounds($scope.mapInstance.getBounds().getNorthEast(),
              $scope.mapInstance.getBounds().getSouthWest());

          });
        },
        idle: function(map) {

          $scope.map.refresh = false;

        },
        resize: function(map) {
          console.log('resize');
        },
        dragend: function() {

        }
      },
      markersEvents: {
        click: function(marker, eventName, model, args) {
          console.log('markerEvent click');
          $scope.map.window.model = model;
          $scope.map.window.show = true;
        }
      },

      window :  {
        marker: {},
        show: false,
        closeClick: function() {
          this.show = false;
        },
        options: {} // define when map is ready
      },

      control: {},
      refresh: function () {
        $scope.map.control.refresh();
      }
    }

    uiGmapGoogleMapApi.then(function (map) {

      $scope.getData(20, 0, map);

      map.visualRefresh = true;
      $scope.mapInstance = map;


    })

       $scope.getData = function(limit, offset, map) {
      Map.getApartments($routeParams.lat, $routeParams.lon, limit, offset).success(function (data) {
         ///----- I get undefined error here---
              $scope.map.control.refresh();



      });

    }})
}

I am not sure how to update the map with new markers or even cause a map update. I played with the "control" and "refresh" options on the ui-gmap-google map, but couldn't make it work.

+4
source share
2 answers

You need to use uiGmapIsReady--- not uiGmapGoogleMapApi--- to wait for objects controlthat need to be supplemented by their methods (for example, refresh).

uiGmapIsReady , , uiGmapGoogleMap , uiGmapGoogleMapApi API- Google Maps.

. uiGmapIsReady. , , .

, , , , . (, getApartments, $scope.apartments? , , - ?) , .

+3

dorebuildall.

<ui-gmap-markers 
    models="apartments"
    coords="'loc'"
    icon="'assets/images/map_icon_normal.png'"
    idkey="'_id'"
    fit="'false'"
    click="click"
    dorebuildall="true">
        <ui-gmap-windows></ui-gmap-windows>
</ui-gmap-markers>

: http://angular-ui.imtqy.com/angular-google-maps/

+1

All Articles