title: How to set marker in google map using javascript
body: <p>I am using the below javascript code to show map and marker.The marker is loading while map load,but i want to load the marker if the button named "Add marker" is clicked.The marker should points to the current location.How to do this here.</p>
  
  <p>js.</p>
  
  <pre><code>&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 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(-29.3456, 151.4346);
    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: 'Marker',
      map: map,
      draggable: true
    });
  }; 
    google.maps.event.addDomListener(window, 'load', initialize);
  &lt;/script&gt;
  </code></pre>
  
  <p>html</p>
  
  <pre><code>&lt;div id="mapCanvas"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Thanks</p>