简体   繁体   中英

click event marker map

I'm loading a map with different markers in an array. I need to generate the click event for each of them and display a message, a balloon or something. Try the following block of code but not turned me leave my code.

Test :

google.maps.event.addListener(marker, 'click', function() {
  map.setZoom(8);
  map.setCenter(marker.getPosition());
});

My code :

<map center="{{latitud}}, {{longitud}}" zoom="12" id="map_views">
              <div id="class" ng-repeat="marker in markers | orderBy : 'title'">
                  <marker position="{{marker.latitud}}, {{marker.longitud}}" />
              </div>
          </map>

Controller :

.controller('MisViewsCtrl',   function($scope,$ionicNavBarDelegate,$timeout,$location,$ionicPlatform,$ionicLoading, $compile){

  $scope.views = [
      {
      id : 0,
      nombre : 'Problema con cableado',
      fecha : '18/05/2014 a las 15:17',
      estado : 'En revisión',
      latitud : -33.3995448,
      longitud : -70.5705277,
      img : 'img/cables.JPG',
      comentario : 'Exiten problemas en el cableado, estan sueltos y es peligroso. Concurre mucha gente por ese lugar.',
      clase : 'label_estado label-warning'
  },
  {
      id : 1,
      nombre : 'Poste en mal estado',
      fecha : '09/11/2013 a las 20:45',
      estado : 'Solucionado',
      latitud : -33.4024754,
      longitud : -70.5919616,
      img : 'img/poste.jpeg',
      comentario : 'El poste esta a punto de caer, se encuentra en una calle muy concurrida por personas y automóviles.',
      clase : 'label_estado label-success'
  },
  {
      id : 2,
      nombre : 'Cañeria rota',
      estado : 'Falta información',
      fecha : '03/03/2012 a las 12:13',
      latitud : -33.406975,
      longitud : -70.57283,
      img : 'img/caneria.jpg',
      comentario : 'Esta rota y oxidada, corre agua por todo el lugar.',
      clase : 'label_estado label-info'

  }
 ];
    $scope.markers = [];
    $scope.createMarker = function(info){
        $scope.markers.push(info); 
    }  

    for (i = 0; i < $scope.views.length; i++){
        $scope.createMarker($scope.views[i]);
    }
})

i think you just cut the event

    google.maps.event.addListener(marker, 'click', function() { map.setZoom(8);
  map.setCenter(marker.getPosition());
    });

to looping marker array try this demo from geocodezip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM