Passing the lat, lng information to the google map script <p>I've have an index.html file that includes a gogglemap.js file to display a map of users location. Currently I am attempting to add the proper code to the index.html to pass the lat, lng info to the js file.</p> <p>Here is filler content for the index file to show what I am attempting to do:</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;h3&gt;&lt;display user city&gt;&lt;/h3&gt; &lt;---- this needs to display users city and has filler text to show what I am trying to accomplish. &lt;div id="map"&gt;&lt;/div&gt; &lt;script&gt;var lat=12.356;var lng=-19.31;var country="User Country";var city="User City";&lt;/script&gt; &lt;----- seems like it is getting the lat/lng somehow before the index page loads and inserting this script into the index file?</code></pre> </div> </div> </p> <p>Here is the js file code:</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var styles = [{yourcustomstyle}] var myLatlng = { lat: lat, lng: lng }; function initialize() { var mapOptions = { zoom: 12, center: myLatlng, styles: styles, panControl: false, zoomControl: false, mapTypeControl: false, scaleControl: false, streetViewControl: false, overviewMapControl: false }; var map = new google.maps.Map( document.getElementById('map'), mapOptions ); for (var a = 0; a &lt; 6; a++) { c = Math.random(); c = c * (0 == 1E6 * c % 2 ? 1 : -1); d = Math.random() d = d * (0 == 1E6 * d % 2 ? 1 : -1); c = new google.maps.LatLng( lat + 0.08 * c + 0.052, lng + 0.2 * d + 0.08), marker = new google.maps.Marker({ map: map, position: c, icon: 'marker.png' }); } } function loadScript() { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&amp;amp;callback=initialize'; document.body.appendChild( script ); } window.onload = loadScript;</code></pre> </div> </div> </p>