angular-google-maps标记未显示

ibo*_*336 3 google-maps angularjs angular-google-maps

所以我使用http://angular-ui.github.io/angular-google-maps/#!/api中的angular-google-maps指令 ,我无法在地图实例上看到我的标记.我已经尝试过几乎所有的东西,我非常渴望得到建议.我已经尝试将$ scope.markers移动到我的$ scope.map对象,尝试将其移动到我的$ watch函数中,并将值直接添加到html中,没有运气.我认为这与我必须添加的$ scope.control.refresh()函数有关,以便地图在选项卡内完全加载(我使用的是angular-bootstrap选项卡).

谢谢你的帮助!

HTML

   <div ng-controller="LocationCtrl" ng-cloak>
  <div class="map-canvas" ng-if="locationActive">
    <ui-gmap-google-map draggable="true" center='map.center' zoom='map.zoom' control="control">
      <ui-gmap-marker coords="markers.coords" idKey="markers.idKey">
      </ui-gmap-marker>
    </ui-gmap-google-map>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JAVASCRIPT

(function() {
  'use strict';

  var locationCtrl = function($scope, uiGmapIsReady, $timeout) {
    $scope.map = {
      center: { latitude: 36.132411, longitude: -80.290481 },
      zoom: 15
    };

    $scope.control = {};

    $scope.active = $scope.$parent.active;
    $scope.locationActive = $scope.active().active;
    $scope.$watch($scope.active, function() {
      $timeout(function() {
        uiGmapIsReady.promise().then(function () {
          $scope.control.refresh();
          var map = $scope.control.getGMap();
          $scope.markers= {
            idKey: 1,
            coords: {
              latitude: 36.132411,
              longitude: -80.290481
            }
          };
        });
      }, 0);
    });
  };
  angular.module('boltlandApp').controller('LocationCtrl', locationCtrl);
})();
Run Code Online (Sandbox Code Playgroud)

Ani*_*niV 7

添加您的HTML:

<ui-gmap-markers models="markers" coords="'coords'" idKey="'idKey'">
          </ui-gmap-markers>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

在你的内心添加这个 $scope.$watch($scope.active, function() {

uiGmapIsReady.promise().then(function () {
         $scope.markers.push({
            idKey: 1,
              coords: {
                latitude: 36.132411,
                longitude: -80.290481
        },        
});
Run Code Online (Sandbox Code Playgroud)