title: Send latitude and longitude to form (to be submitted to database)
body: <p>I have a google map that displays my current location and when I click on the map a new marker is added that displays the latitude and longitude in an infowindow.  I'm happy with that.</p>
  
  <p>What I want to happen is for that latitude and longitude to be entered into a form I have on the same page with details about that location.  That info will then be sent to a database.</p>
  
  <p>This is the javascript:</p>
  
  <pre><code>var map;
  var marker2;
  var infowindow2;
  var infowindow;
  function getLocation() 
  {
  if (navigator.geolocation) 
  {
      navigator.geolocation.getCurrentPosition(showPosition, placeMarker, showError);
  }
  else
  {
      x.innerHTML = "Geolocation is not supported by this browser.";
  }  
  }
  function showPosition(position)
  {
      lat2 = position.coords.latitude;
  lon = position.coords.longitude;
  latlon = new google.maps.LatLng(lat2, lon)
  mapholder = document.getElementById('mapholder')   
  
  var mapProp = 
  {
      center: latlon, zoom: 17,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      mapTypeControl: false,
      navigationControlOptions:{style: google.maps.NavigationControlStyle.SMALL}
  };
  
  map = new google.maps.Map(document.getElementById("mapholder"),mapProp);
  var marker = new google.maps.Marker({ position: latlon, map:map, title: "You are Here"});
  marker.setMap(map);
  infowindow2 = new google.maps.InfoWindow({ content:"You are Here!" + "&lt;br&gt;Click on desired location to generate latitute and longitude coordinates;" + "&lt;br&gt;Click 'Send' to enter Latitude and Longitude co-ordinates into form"});
  infowindow2.open(map,marker);
  
  google.maps.event.addDomListener(window, 'load', getLocation);
  google.maps.event.addListener(map, 'click', function(event) 
  {
      placeMarker(event.latLng);
  });
  }
  function placeMarker(location) 
  {
   if (!marker2) 
   {
       marker2 = new google.maps.Marker({ position: location, map: map, icon: 'Icon/aed4.jpg' });
   }
   else 
   {
       marker2.setPosition(location);
   }
  
   google.maps.event.addListener(marker2, 'click', function (event) 
   {
       document.getElementById("latbox").value = event.lat();
       document.getElementById("lngbox").value = event.lng();
   });
  
   infowindow = new google.maps.InfoWindow({ content: 'Latitude: ' + location.lat() + '&lt;br&gt;Longitude: ' + location.lng() });
   infowindow.open(map, marker2);
   infowindow2.close(map, marker2);
  
   google.maps.event.addDomListener(window, 'load', showPosition);
  }
  google.maps.event.addDomListener(window, 'load', placeMarker);
  infowindow.close(map, marker2);
  </code></pre>
  
  <p>This is the form I want to place it in:</p>
  
  
          
  
  <pre><code>    &lt;div id="formlocation"&gt;
          &lt;table class="style1"&gt;
              &lt;tr&gt;
                  &lt;td class="style2"&gt;
                      &lt;asp:Label ID="buildingLbl" runat="server" Text="Building Name:"&gt;&lt;/asp:Label&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="buildingTxt" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              Latitude:&lt;input size="20" id="latbox" type="text" name="lat" /&gt;
              &lt;br /&gt;
              Longitude:&lt;input size="20" id="lngbox" type="text" name="lng" /&gt;
              &lt;br /&gt;
  </code></pre>
  
  <p>I tried putting them into a textbox but couldn't get that working either.</p>
  
  <p>Also, will I be able to send the info from the input area into SQL the same as the textbox?</p>
  
  <p>I thought I found the answer <a href="https://stackoverflow.com/questions/5968559/retrieve-latitude-and-longitude-of-a-draggable-pin-via-google-maps-api-v3">here</a> but cant figure what I'm doing wrong - hopefully there's a nice simple solution - I'm a novice...  All help appreciated.</p>
  
  <p>I was thinking something like this website <a href="http://www.gorissen.info/Pierre/maps/googleMapLocationv3.php" rel="nofollow noreferrer">EXAMPLE</a>.  I will only have 1 marker that can be moved by clicking on map and this changes the values in the latitude and longitude fields.</p>
  
  <p>I was adding in screenshot of what I have so far but I cant until I have 10 reputations... I want the coords to populate the fields as the marker is moved by clicking on the map.  I know I have in the InfoWindow to click 'Send' to enter co-ordinates into form but ideally it will change as you move the marker by clicking on the map.</p>
  
  <p>I want the Latitude and Longitude values from the infoWindow to go into the form.  I have two fields for Latitude and Longitude in my example but that is from me trying to get the values into a TextBox and input field.  </p>
  
  <p>There should be a 'Submit' button at the bottom of the form that sends all the information to a database (SQL).</p>
  
  <p>Hope this helps explain what I'm after...</p>