角度贴图:无法从markersScope获取gMarker

时间:2015-01-24 14:54:33

标签: javascript angularjs google-maps

我在尝试添加infoWindows时收到Unable to get gMarker from markersScope!(在角度地图中https://github.com/angular-ui/angular-google-maps/blob/master/src/coffee/directives/api/models/parent/windows-parent-model.coffee#L146)。窗口会显示,但在更新时表现不正常。

每次用户点击电影时,infoWindows都应该在该电影院标记处更新有关该电影的信息。它有时会起作用,有时infoWindows会消失,有时标记也会消失。我得到的唯一错误是上面的错误。

控制器和视图代码:

var createCinemaMarkers = function(cinemas) {
  $scope.cinemaMarkers = [];
  $scope.cinemaWindows = [];
  for (var i = 0; i < cinemas.length; i++) {

    getMoviesForCinema(cinemas[i].venue_id);

    var map_coords = {
      id: cinemas[i].venue_id,
      title: cinemas[i].title,
      options: {
        title: cinemas[i].title,
        random: 'blah blah blah'
      },
      clickable: true,
      latitude: cinemas[i].coords.lat,
      longitude: cinemas[i].coords.lng,
      icon: 'images/cinema_icons/cinema.png'
    }

    if (!cinemas[i].movieTitle) {
      cinemas[i].movieTitle = '';
    }

    var parameters = {
        movieTitle: cinemas[i].movieTitle,
        movieTimes: cinemas[i].movieTimes,
        stuff: 'from props'
    }

    var infoWindow = {
      id: cinemas[i].venue_id,
      coords: {
        latitude: cinemas[i].coords.lat,
        longitude: cinemas[i].coords.lng
      },
      options: {
        title: "I AM TITLE"
      },
      show: true,
      templateUrl: 'views/info-window.html',
      templateParameter: parameters,
      isIconVisibleOnClick: true,
      closeClick: 'none'
    }

  $scope.cinemaWindows.push(infoWindow);      
  $scope.cinemaMarkers.push(map_coords);
  };
};

    <ui-gmap-google-map center="map.center" zoom="map.zoom" events="mapEvents">
    <ui-gmap-markers models="cinemaMarkers" events="events" options="'options'" coords="'self'" icon="'icon'" fit="'true'"  popover-placement="top" popover="On the Top!">
        <ui-gmap-windows models="cinemaWindows" templateUrl="'templateUrl'" templateParameter="'templateParameter'" options="'options'">
        </ui-gmap-windows>
    </ui-gmap-markers>
</ui-gmap-google-map>

1 个答案:

答案 0 :(得分:0)

我有一个类似的问题,在指令coords =&#34;&#39; self&#39;&#34;但标记设置为坐标:{纬度:xxxx,经度:xxxxx}

因为您的ui-gmap-markers设置为coords =&#34;&#39; self&#39;&#34;所以请尝试删除infoWindow中的 coords

var infoWindow = {
      id: cinemas[i].venue_id,
      latitude: cinemas[i].coords.lat,
      longitude: cinemas[i].coords.lng,
      options: {
        title: "I AM TITLE"
      },
      show: true,
      templateUrl: 'views/info-window.html',
      templateParameter: parameters,
      isIconVisibleOnClick: true,
      closeClick: 'none'
    }