title: how to get points return from OpenLayers.Control.DrawFeature
body: <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" debug="true"&gt;
    &lt;head&gt;
  
  
  &lt;title&gt;Mapping project&lt;/title&gt;
  &lt;link rel="stylesheet" href="default/style.css" type="text/css"&gt;
  &lt;link rel="stylesheet" href="example/style.css" type="text/css"&gt;
  &lt;script src="js/jquery-1.8.2.js"&gt;&lt;/script&gt;
  &lt;script src="OpenLayers/OpenLayers.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
    var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
    var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
    var extent = new OpenLayers.Bounds(85.27004687475169, 27.65583205563965, 85.37218539403848,27.74656781293908).transform(fromProjection,toProjection);
  
    var position       = new OpenLayers.LonLat(85.322136566277, 27.698144266444).transform( fromProjection, toProjection);
    var zoom           = 13; 
    var map, vectors, drawControls, wkt;
    var c=0; 
  
      function init(){
         var newLayer = new OpenLayers.Layer.OSM();
         var opt = {restrictedExtent : extent};
          vectors = new OpenLayers.Layer.Vector("Overlayers");
  
          map = new OpenLayers.Map("map", opt);
          map.addLayer(newLayer, vectors);
          map.addControl(new OpenLayers.Control.LayerSwitcher());
          map.addControl(new OpenLayers.Control.MousePosition());
  
          // var options = {
          //     hover: true,
          //     onSelect: displayWKT
          // };
  
          //Defining type of draw controls
          drawControls = {
              point: new OpenLayers.Control.DrawFeature(vectors,
                          OpenLayers.Handler.Point),
              line: new OpenLayers.Control.DrawFeature(vectors,
                          OpenLayers.Handler.Path),
              polygon: new OpenLayers.Control.DrawFeature(vectors,
                          OpenLayers.Handler.Polygon)
          };
  
          //Controls are add to the map
          for(var key in drawControls) {
              map.addControl(drawControls[key]);
          }
          wkt = new OpenLayers.Format.WKT();
  
          //Center positiona and height of zoom of the map is set here
          map.setCenter(position, zoom);  
  
  
          /*************************This is event register for mouse*******************************/
  
          map.events.register("click", map, function(e) {
  
  
  
              if(c==1){
                var lonlat = map.getLonLatFromPixel(e.xy).transform(map.getProjectionObject(), fromProjection);
                var lon = lonlat.lon;
                var lat = lonlat.lat;
  
                 $('.form-block').css('display','block');  
                 $('#lngval').attr('value',lon);              
                 $('#latval').attr('value',lat); 
  
                var position= new OpenLayers.LonLat(lon,lat).transform( fromProjection, toProjection);
                var markers = new OpenLayers.Layer.Markers( "Markers" );
                map.addLayer(markers);
                markers.addMarker(new OpenLayers.Marker(position));
              }else{
                alert("please select any one control");
              }
  
  
  
        });
  
        /******************Mouse click events ends here******************************************/
  
      }
  
       function toggleControl(element) {
          for(key in drawControls) {
              var control = drawControls[key];
              if(element.value == key) {
                  control.activate();
                  c=1;
              } else {
                  control.deactivate();
              }
          }
      }
  
      // function displayWKT(feature) {
      //     var str = wkt.write(feature);
      //     // not a good idea in general, just for this demo
      //    // str = str.replace(/,/g, ', ');
      //    // document.getElementById('wkt').innerHTML = str;
      //    $('#wkt').attr('value',"abc");
      // }
  
      function parseWKT() {
          var element = document.getElementById('wkt');
          var features = wkt.read(element.value);
          var bounds;
          if(features) {
              if(features.constructor != Array) {
                  features = [features];
              }
              for(var i=0; i&lt;features.length; ++i) {
                  if (!bounds) {
                      bounds = features[i].geometry.getBounds();
                  } else {
                      bounds.extend(features[i].geometry.getBounds());
                  }
  
              }
              vectors.addFeatures(features);
              var plural = (features.length &gt; 1) ? 's' : '';
              element.value = 'Feature' + plural + ' added'
          } else {
              element.value = 'Bad WKT';
          }
      }
  
    &lt;/script&gt;
  
  
  &lt;/head&gt;  
  
    &lt;body onload="init()"&gt;
    &lt;?php
      if(isset($_POST['submit']))
      {
        $con = dbConnect();
          $type = $_POST['type'];
          $lng = $_POST['lng'];
          $lat = $_POST['lat'];
          $des = $_POST['des'];
  
      $sql = "Insert into pointdetails values('null', '$type','$lng,$lat','$des')";
      mysql_query($sql) or die(mysql_error());
  
    dbClose($con);
  
  }
  function dbConnect()
  {
        $con = mysql_connect("localhost","root","");
        if (!$con)
        {
          die('Could not connect: ' . mysql_error());
        }
        else
        {
          mysql_select_db("mapping", $con);
          return $con;
        }
  }
  
  function dbClose($con)
  {
    mysql_close($con);
  }
  
  
  
   ?&gt;
  
    &lt;?php 
  
          $con = dbConnect();
            $sql = "select * from place";
            $result = mysql_query($sql);
  
            while($row=mysql_fetch_array($result))
            {
             $options[$row['id']]=$row['name']; 
            }
        //var_dump($options);
      dbClose($con);
  
       ?&gt;
  
       &lt;input type="button" value="point" id="pointToggle" name="Draw point" onclick="toggleControl(this);"/&gt;
       &lt;input type="button" value="line" id="lineToggle" name="Draw line" onclick="toggleControl(this);"/&gt;
       &lt;input type="button" value="polygon" id="polygonToggle" name="Draw polygon" onclick="toggleControl(this);"/&gt;
       &lt;p&gt;
     &lt;div class="wrapper"&gt;
      &lt;div id="map" class="smallmap"&gt;&lt;/div&gt;
  
      &lt;div class="form-block"&gt;
        &lt;form action="index.php" method="post"&gt;&lt;p&gt;
        &lt;label&gt;Type: &lt;/label&gt;
  
          &lt;select name="type"&gt;
              &lt;?php foreach($options as $key=&gt;$value): ?&gt;
              &lt;option value="&lt;?php echo $key; ?&gt;"&gt;&lt;?php echo $value; ?&gt;&lt;/option&gt;
              &lt;?php endforeach; ?&gt;
              &lt;/select&gt;
              &lt;/p&gt;
              &lt;p&gt;
              &lt;label&gt;Long&lt;/label&gt;
              &lt;input type="text" value="" id="lngval" name="lng"&gt;&lt;/p&gt;
          &lt;p&gt;&lt;label&gt;Lat&lt;/label&gt;
          &lt;input type="text" value="" id="latval" name="lat"&gt;&lt;/p&gt;
          &lt;p&gt;&lt;label&gt;Describe&lt;/label&gt;
          &lt;textarea rows="4" cols="16" name="des"&gt;&lt;/textarea&gt;&lt;/p&gt;
          &lt;input type="submit" value="Submit" name="submit"&gt;
        &lt;/form&gt;
  
      &lt;/div&gt;
      &lt;div&gt;  &lt;textarea rows="4" cols="16" name="wkt" id="wkt"&gt;&lt;/textarea&gt;
        &lt;p&gt;&lt;input type="submit" value="feature" name="feature" onclick="parseWKT();"&gt;&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Above program is to get the coordinate to marked point, polygons etc and save it in database in WKT format.I am completely beginner to this thing.. Please i need your help. Currently i am stuck in getting cordinates. When i select any control(say polygon), i will be able to draw it in map but i need to get all that coordinates.. I have not idea to continue..  Please help me with this....</p>
  
  <p>THanks in advance</p>