title: How to load maps only once the permission is granted
body: <p>I am developing one classified portal their user can post their ads and I used Google geolocation feature to get the user's current location coordinates form the browser.</p>
  
  <p>The browser asking to grant permission, But I want to only display the map if only the permission is granted. If not I have to put some default coordinates for the location.</p>
  
  <p>Here is my current code :</p>
  
  <pre><code>  &lt;div id="map"&gt;&lt;/div&gt;
      &lt;script&gt;
        // Note: This example requires that you consent to location sharing when
        // prompted by your browser. If you see the error "The Geolocation service
        // failed.", it means you probably did not give permission for the browser to
        // locate you.
        var map, infoWindow;
        function initMap() {
          map = new google.maps.Map(document.getElementById('map'), {
            center: {lat: -34.397, lng: 150.644},
            zoom: 13
          });
          infoWindow = new google.maps.InfoWindow;
              document.cookie = "myJavascriptVar=12345";
  
  
          // Try HTML5 geolocation.
          if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function(position) {
              var pos = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
              };
              var my_marker = new google.maps.Marker({
                         position: pos,
                         map: map,
                         "icon": 'map.png',
                         draggable: true,
                     });
  
              infoWindow.setPosition(pos);
              //infoWindow.setContent('You are here');
              infoWindow.open(map);
              map.setCenter(pos);
            }, function() {
              handleLocationError(true, infoWindow, map.getCenter());
            });
          } else {
            // Browser doesn't support Geolocation
            handleLocationError(false, infoWindow, map.getCenter());
          }
        }
  
        function handleLocationError(browserHasGeolocation, infoWindow, pos) {
          infoWindow.setPosition(pos);
          infoWindow.setContent(browserHasGeolocation ?
                                'Error: The Geolocation service failed.' :
                                'Error: Your browser doesn\'t support geolocation.');
          infoWindow.open(map);
        }
  
  
  </code></pre>
  
  <p>How I can check if browser permission is granted or not ?</p>
  
  <p>Why it asking every time I refresh the page ?</p>