Geolocation does not work when closing and opening the modal

0

Geolocation only works the first time I open the modal, if I close and open again it just does not work

Strangely if I change browser tab and return it works, I am using chrome in linux

Follow the problem gif

  

link

var map, GeoMarker;

function initialize() {
  var mapOptions = {
    zoom: 17,
    center: new google.maps.LatLng(-34.397, 150.644),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById('map_canvas'),
    mapOptions);

  GeoMarker = new GeolocationMarker();
  GeoMarker.setCircleOptions({
    fillColor: '#808080'
  });

  google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {
    map.setCenter(this.getPosition());
    map.fitBounds(this.getBounds());
  });

  google.maps.event.addListener(GeoMarker, 'geolocation_error', function(e) {
    alert('There was an error obtaining your position. Message: ' + e.message);
  });

  GeoMarker.setMap(map);
}

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

if (!navigator.geolocation) {
  alert('Your browser does not support geolocation');
}


$('#large-dialog').on('shown.bs.modal', function(e) {
  initialize();
});
html,
body,
#map_canvas {
  margin: 0;
  padding: 0;
  height: 300px;
  width: 300px
}
<link href="https://propeller.in/assets/css/propeller.min.css" rel="stylesheet" />
<link href="https://propeller.in/assets/css/bootstrap.min.css" rel="stylesheet" />

<script src="https://propeller.in/assets/js/jquery-1.12.2.min.js"></script><scriptsrc="https://propeller.in/assets/js/bootstrap.min.js"></script>
<script src="https://propeller.in/assets/js/propeller.min.js"></script><scriptsrc="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://chadkillingsworth.github.io/geolocation-marker/geolocation-marker.js"></script><buttondata-target="#large-dialog" data-toggle="modal" class="btn pmd-ripple-effect btn-primary pmd-z-depth" type="button">Large Modal</button>
<div tabindex="-1" class="modal fade" id="large-dialog" style="display: none;" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>

        <div class="modal-body">
          <div id="map_canvas"></div>
          <!-- no working -->
        </div>

      </div>
    </div>
  </div>
</div>
    
asked by anonymous 24.01.2018 / 22:15

0 answers