How to get only one marker in the Google Maps API with JavaScript
<p>My code:</p>
<pre><code>&lt;script
src=&quot;http://maps.googleapis.com/maps/api/js&quot;&gt;
&lt;/script&gt;

&lt;script&gt;
var map;
var myCenter=new google.maps.LatLng(51.508742,-0.120850);

function initialize()
{
var mapProp = {
  center:myCenter,
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };

  map = new google.maps.Map(document.getElementById(&quot;googleMap&quot;),mapProp);

  google.maps.event.addListener(map, 'click', function(event) {
    placeMarker(event.latLng);
  });
}

function placeMarker(location) {
  var marker = new google.maps.Marker({
    position: location,
    map: map,
  });
  var infowindow = new google.maps.InfoWindow({
    content: 'Latitude: ' + location.lat() + '&lt;br&gt;Longitude: ' + location.lng()
  });
  infowindow.open(map,marker);
}

google.maps.event.addDomListener(window, 'load', initialize);
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;googleMap&quot; style=&quot;width:500px;height:380px;&quot;&gt;&lt;/div&gt;
</code></pre>
<p>I've got every kilometer a new marker. How can I remove the other if I click it again?</p>
<p>Btw: read this :<a href="https://stackoverflow.com/questions/12232370/google-maps-how-to-get-to-show-only-one-marker">Google Maps how to get to show only one marker?</a></p>
<p>Wanted to use it, but it doesn't work (in console: CurrentPosition() and watchPosition() are deprecated on insecure origins, and support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See <a href="https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins" rel="nofollow noreferrer">https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins</a> for more details.)</p>