title: Failed in clear markers in Google Map API3
body: <p>I have created a function to add the marker when there is no marker on map or remove the original marker and added a new one to replace it. However, i can add the first part of script successfully to add the marker on map. however, the original marker can not be removed and new marker could not added when i click the map again. Can anyone suggest what is the problem?</p>
  
  <pre><code>/*Create a listener to record the Click event of the google map and define it as the starting point (i.e. Origin in Google Direction
  service*/
  google.maps.event.addListener(map, 'click', function(event) {
    if (origin == null) {
      origin = event.latLng;
  
      lat = origin.lat();
      lng = origin.lng();
      UpdateLatLng();  
  
      var startimage = 'images/Start4.png';
      StartMarker = new google.maps.Marker({
           map: map,
           position: origin,
           icon: startimage
       });
    } else {
   //Relocate the Starting point and assign the new position to Textbox
      alert ("The starting point was relocated on screen"); 
      StartMarker.setMap(null);
      directionsDisplay.setMap(null);
      directionsDisplay.setPanel(null);
      directionsDisplay.setDirections({routes: []});
      var origin = event.latLng;  
      lat = origin.lat();
      lng = origin.lng();
      UpdateLatLng(); 
      var startimage = 'images/Start4.png';
      StartMarker = new google.maps.Marker({
           map: map,
           position: origin,
           icon: startimage
       });
      } 
  }); 
  </code></pre>