title: how to get longitude and latitude of google maps in javascript
body: <p>i am using google maps with java script it is working fine i need to get the current longitude and latitude and save it to database,the trick is the pointer is draggable so how can i get the current long and lat?</p>
  
  <pre><code>function markernew(){
  
  
  markers = [];
  //var val=document.getElementById('val2').value=;
   $("#floating-panel").show();
     var latlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
          zoom: 1,
          center: latlng,
        mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
        navigationControl: true,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
        if(marker) marker.setMap(null);
        var geocoder;
        var address ="";
    if(!document.getElementById('address_id').value){
   alert('Enter Address');
    }
    else if (!document.getElementById('city_id').value){
   alert('Enter City');
    }
    else if (!document.getElementById('nearby_id').value){
     alert('Enter Country');
    }
    else{
       $("#findplace").show();
      var address="";
     var array = document.getElementById('address_id').value;
     array+=",";
  
     if(array.match(/,/g).length==1){
    array = array.split(',');
     address += array[0]+" ";
      address += array[1];
  
     }
  
     else if(array.match(/,/g).length==2){
      array = array.split(',');
       address += array[0]+" ";
      address += array[1]+" ";
      address += array[2];
  
     }
     else if(array.match(/,/g).length==3){
      array = array.split(',');
       address += array[0]+" ";
      address += array[1]+" ";
      address += array[2]+" ";
        address += array[3];
  
     }
      else if(array.match(/,/g).length==4){
       array = array.split(',');
       address += array[0]+" ";
      address += array[1]+" ";
      address += array[2]+" ";
        address += array[3]+" ";
            address += array[4];
     }
     else if(array.match(/,/g).length==5){
       array = array.split(',');
       address += array[0]+" ";
      address += array[1]+" ";
      address += array[2]+" ";
        address += array[3]+" ";
       address += array[4]+" ";
    address += array[5];
     }
     else{
      alert("inside else");
     var address= document.getElementById('address_id').value; 
            }
  
    // address += document.getElementById('address_id').value + " ";
      address += document.getElementById('city_id').value + " ";
      address += document.getElementById('nearby_id').value;
  
      geocoder = new google.maps.Geocoder();
  
      if (geocoder) {
        geocoder.geocode( { 'address': address}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
            map.setCenter(results[0].geometry.location);
  
              map.setZoom(15);
              var infowindow = new google.maps.InfoWindow(
                  { content: '&lt;b&gt;'+address+'&lt;/b&gt;',
                    size: new google.maps.Size(150,50)
                  });
  
              google.maps.event.addListener(map, 'click', function(event) {
  
      if(abc==true){
       placeMarker(event.latLng);
       abc=false;
        }
       });
  
            } else {
              alert("No results found");
            }
          } else {
            alert("Geocode was not successful for the following reason: " + status);
          }
        });
      }
    }
  
    }
     function placeMarker(location) {
  
      var marker = new google.maps.Marker({
          position: location, 
          map: map,
    draggable:true
      });
   markers.push(marker);
  
  
    var infowindow = new google.maps.InfoWindow({
      content: 'Latitude: ' + location.lat() + '&lt;br&gt;Longitude: ' + location.lng()
    });
    infowindow.open(map,marker);
  }
  function setMapOnAll(map) {
    for (var i = 0; i &lt; markers.length; i++) {
      markers[i].setMap(map);
    }
  }
  function clearMarkers() {
    setMapOnAll(null);
  }
  
  function deleteMarkers() {
    clearMarkers();
    abc=true;
    markers = [];
  }
  </code></pre>