Maps API Cordova - Add multiple markers

1

I'm using the code below to add multiple markers on the map. With each click a marker is added. In Chrome the code works perfectly, however, when generating the code using cordova the map is displayed but no bookmarks are added.

        function initialize() {
          var inicial = { lat: -22.4086028, lng: -43.6624047 };
          var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 17,
            center: inicial
          });

        google.maps.event.addListener(map, 'mousedown', function(event) {
          var initPoint = {x: event.pageX, y: event.pageY},
          toBeCanceled = false,
          latLong = event.latLong;

          google.maps.event.addListener(map, 'mousemove', function(event) {
            var newPoint = {x: event.pageX, y: event.pageY};
            toBeCanceled = true
          });

          google.maps.event.addListener(map, 'mouseup', function(event) {
            if (toBeCanceled) {
              event.stop()
            } else {
              addMarker(event.latLng, map);
              console.log(event.latLng.lat() +' _ ' + event.latLng.lng());
              salvaPonto(event.latLng.lat(), event.latLng.lng());
              event.latLng.empty();
            }
          });

        });

        }

        function addMarker(location, map) {
            var marker = new google.maps.Marker({
              position: location,
              label: "D",
              map: map
            });

        }


  google.maps.event.addDomListener(window, 'load', initialize);
    
asked by anonymous 02.08.2016 / 00:52

1 answer

0

Try this:

addMarkers(data, function(markers) {
  markers[markers.length - 1].showInfoWindow();
});

function addMarkers(data, callback) {
  var markers = [];
  function onMarkerAdded(marker) {
    markers.push(marker);
    if (markers.length === data.length) {
      callback(markers);
    }
  }
  data.forEach(function(markerOptions) {
    map.addMarker(markerOptions, onMarkerAdded);
  });
}

Info: link

    
02.08.2016 / 06:34