Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(angularjs谷歌地图)点击标记内_Angularjs_Google Maps_Angularjs Directive_Angularjs Google Maps - Fatal编程技术网

(angularjs谷歌地图)点击标记内

(angularjs谷歌地图)点击标记内,angularjs,google-maps,angularjs-directive,angularjs-google-maps,Angularjs,Google Maps,Angularjs Directive,Angularjs Google Maps,这个问题是关于angularjs谷歌地图的 有没有一种方法可以使用ng单击标记来设置这样的变量?(1的值为硬编码,用于测试目的)。当前单击标记似乎不会触发ng单击 <marker ng-repeat="instance in common.instances" position="[{{instance.lat}},{{instance.lng}}]" ng-click="common.selectedinstance = 1"> </marker> 从他们的

这个问题是关于angularjs谷歌地图的

有没有一种方法可以使用ng单击标记来设置这样的变量?(1的值为硬编码,用于测试目的)。当前单击标记似乎不会触发ng单击

<marker ng-repeat="instance in common.instances" 
 position="[{{instance.lat}},{{instance.lng}}]" 
 ng-click="common.selectedinstance = 1">
</marker>

从他们的文档中

用户事件(如“单击”鼠标事件)从DOM传播 到谷歌地图API。这些事件是独立的不同的 标准DOM事件

据我所知,只有谷歌地图事件可以应用于谷歌地图对象,包括标记、形状等

这是个坏消息

好消息是,您仍然可以使用单击事件上的
来操作
$scope
变量和事件。只要对该事件使用函数,就不会有太大区别

我将继续调查是否有解决办法,以便我们可以使用AngularJS事件(即ngMouseenger、ngMouseleave.ngMouseup、ngClick等)

plunkr提供了一个使用点击的工作示例,以满足您的需求

这是脚本部分

  $scope.myVar = 1;
  $scope.changeMyVar = function(event) {
    $scope.myVar+=1;
    $scope.$apply();
  }
这是html部分

  <map zoom="11" center="[40.74, -74.18]">
    <marker ng-repeat="p in positions" 
      position="{{p}}" title="{{p.toString()}}"
      on-click="changeMyVar()">
    </marker>
  </map>
  myVar : {{myVar}}  Click a marker to increase myVar

myVar:{{myVar}}单击一个标记以增加myVar

要了解更多关于angularjs google maps事件的信息,请查看我在下面代码中使用的获取点击标记的纬度和经度的代码

Html:


@AntoineCloutier,谢谢你的报道。我做了一个修复。
   <ng-map zoom="12" center="{{vm.geoCenterLoc}}" style="height:500px">
            <marker ng-repeat="p in vm.positions"
                    position="{{p.pos}}"
                    data="{{data[$index]}}"
                    on-click="myFunc($event)";
                    title="pos: {{p.pos}}"></marker>
   </ng-map>
 $scope.myFunc = function (evt) {

            markerPosObj = {
                pos: [this.getPosition().lat(), this.getPosition().lng()]
            };
            markerPos = [];
            markerPos.push(markerPosObj);
            console.log('this marker', markerPos);
        }