title: Getting general location of user with google maps
body: <p>I'm trying to get a general location of the user, reasons irrelevant, but I can't use the API to get their location. I've tried to parse the data associated with the IP, but if I have the $.getJson() outside of the initMap() function, the variables aren't changed and if inside initMap(), initMap() isn't recognised as a function.</p>
  
  <p>tl:dr - how do I call the $.getJSON from inside the initMap() function?</p>
  
  <p>Here's What I've tried:</p>
  
  <pre><code>&lt;div id="map" style="width: 100%; height: 100%;; "&gt;&lt;/div&gt;
          &lt;!-- G-Maps box-sizing: border-box; --&gt;
  
          &lt;script&gt;
              var usrLat = 0;
              var usrLon = 0;
  
              function initMap() {
                  var map = new google.maps.Map(document.getElementById('map'), {
                      zoom: 6,
  
                      $.getJSON("https://freegeoip.net/json/", function (data) {
                                          usrLat = parseFloat(data.latitude);
                                          usrLon = parseFloat(data.longitude);
                                          console.log(usrLon + ", " + usrLat);
                                          });
  
                      center: {lat: usrLat, lng: usrLon},
                      mapTypeControl: true,
                      scrollwheel: false,
                      navigationControl: false,
                      mapTypeControl: false,
                      scaleControl: false,
                      draggable: false,
                      mapTypeId: google.maps.MapTypeId.ROADMAP,
                      disableDefaultUI: true,
                      mapTypeControlOptions: {
                      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
                      mapTypeIds: ['roadmap', 'terrain']
                      }
                  });
              }
          &lt;/script&gt;
  </code></pre>