N
N
nixischev2014-01-27 14:25:44
Google Maps
nixischev, 2014-01-27 14:25:44

Google Maps - marks and information windows for them

Good day!
There is a table with coordinates, after receiving these coordinates, you need to add markers to the Google Maps map and attach a specific info window to each marker, tell me how to do this? Here are my work:

var gmap = {
  map : [],
  markers : [],

  init : function(){
    var mapOptions = {
      zoom: 15,
    };
    map = new google.maps.Map(document.getElementById('map-canvas'),
        mapOptions);

    google.maps.event.addListener(map, 'click', function(coordinates) {
      var coords = {
        lat : coordinates.latLng.d,
        lng : coordinates.latLng.e,
      };
      gmap.addMarker(map,coords);
    });

    gmap.geo();
  },

  loadMarkers : function(data){
    /* как сделать вывод маркеров и инфоокон? */
  }

  addMarker : function(mapObj,coords){
    
    var marker = new google.maps.Marker({
      	position: coords,
      	map: mapObj,
      	icon: 'img/marker-32x32.png',
      	animation: google.maps.Animation.DROP,
    });
    
    listener.tmp.marker = marker; //удалит маркер, если модальное окно будет закрыто
    dialog.addPlace(marker);
  },

  deleteMarker : function(marker){
    marker.setMap(null);
  },

  geo : function(){
    // Try HTML5 geolocation
    if(navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var pos = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);

        var infowindow = new google.maps.InfoWindow({
          map: map,
          position: pos,
          content: 'Location found using HTML5.'
        });
        map.setCenter(pos);
      }, function() {
        gmap.geoError(true);
      });
    } else {
      // Browser doesn't support Geolocation
      gmap.geoError(false);
    }
  },

  geoError : function(errorFlag) {
    if (errorFlag) {
      var content = 'Error: The Geolocation service failed.';
    } else {
      var content = 'Error: Your browser doesn\'t support geolocation.';
    }

    var options = {
      map: map,
      position: new google.maps.LatLng(-34.397, 150.644),
      content: content
    };

    var infowindow = new google.maps.InfoWindow(options);
    map.setCenter(options.position);
  },
};



google.maps.event.addDomListener(window, 'load', gmap.init);

the functionality should be written either in the loadMarkers function or in the html code
pS: I know what to run through foreach, the question is what to run in order to get markers on the map and info windows for them (when clicking on the market)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question