title: Google Maps API v3 marker coordinates
body: <p>I use Google Maps API v3 in my asp content page. I have got a marker in my map, and I need to save the markers coordinates in database. In the .aspx folder the markers coordinates I can show in a <code>&lt;div id="indo"&gt;&lt;div&gt;</code>. How can I get the marker coordinates in my .aspx.cs file?<br>
  <a href="http://gmaps-samples-v3.googlecode.com/svn/trunk/draggable-markers/draggable-markers.html" rel="nofollow">Google example</a>
  <br>
  My code:
  <br></p>
  
  <pre><code>&lt;%@ Page Title="Dragable Marker Address" Language="C#" MasterPageFile="~/TesztMasterPage.Master" AutoEventWireup="true" CodeBehind="TesztContentPage2.aspx.cs" Inherits="Google1.TesztContentPage2" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"&gt;
      &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" /&gt;
      &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
      var geocoder = new google.maps.Geocoder();
  
      function geocodePosition(pos) {
          geocoder.geocode({
              latLng: pos
          }, function (responses) {
              if (responses &amp;&amp; responses.length &gt; 0) {
                  updateMarkerAddress(responses[0].formatted_address);
              } else {
                  updateMarkerAddress('Cannot determine address at this location.');
              }
          });
      }
  
      function updateMarkerStatus(str) {
          document.getElementById('markerStatus').innerHTML = str;
      }
  
      function updateMarkerPosition(latLng) {
          document.getElementById('info').innerHTML = [
      latLng.lat(),
      latLng.lng()
    ].join(', ');
      }
  
      function updateMarkerAddress(str) {
          document.getElementById('address').innerHTML = str;
      }
  
      function initialize() {
          var latLng = new google.maps.LatLng(-34.397, 150.644);
          var map = new google.maps.Map(document.getElementById('mapCanvas'), {
              zoom: 8,
              center: latLng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
          });
          var marker = new google.maps.Marker({
              position: latLng,
              title: 'Point A',
              map: map,
              draggable: true
          });
  
          // Update current position info.
          updateMarkerPosition(latLng);
          geocodePosition(latLng);
  
          // Add dragging event listeners.
          google.maps.event.addListener(marker, 'dragstart', function () {
              updateMarkerAddress('Dragging...');
          });
  
          google.maps.event.addListener(marker, 'drag', function () {
              updateMarkerStatus('Dragging...');
              updateMarkerPosition(marker.getPosition());
          });
  
          google.maps.event.addListener(marker, 'dragend', function () {
              updateMarkerStatus('Drag ended');
              geocodePosition(marker.getPosition());
          });
      }
  
      // Onload handler to fire off the app.
      google.maps.event.addDomListener(window, 'load', initialize);
  &lt;/script&gt;
  &lt;style type="text/css"&gt;
    #mapCanvas {
      width: 500px;
      height: 400px;
      float: left;
    }
    #infoPanel {
      float: left;
      margin-left: 10px;
    }
    #infoPanel div {
      margin-bottom: 5px;
    }
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;/asp:Content&gt;
  
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt;
      &lt;div id="mapCanvas"&gt;&lt;/div&gt;
      &lt;div id="infoPanel"&gt;
          &lt;b&gt;Marker status:&lt;/b&gt;
          &lt;div id="markerStatus"&gt;&lt;i&gt;Click and drag the marker.&lt;/i&gt;&lt;/div&gt;
          &lt;b&gt;Current position:&lt;/b&gt;
          &lt;div id="info"&gt;&lt;/div&gt;
          &lt;b&gt;Closest matching address:&lt;/b&gt;
          &lt;div id="address"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/asp:Content&gt;
  </code></pre>