Hi all,<div><br></div><div>I have a simple application which adds a marker using the geolocation api after a button click. The issue is that each time the user clicks, another marker is placed. This isn&#39;t really a problem, but for aesthetic purposes, I&#39;d like to destroy or remove the first marker if the clicks again, rather than show a series of markers at or close to the user&#39;s position because geolocation based on IP seems to shift it&#39;s calculated position, which is I guess has to do with variations of which servers the users traffic is being routed through at the time of the call to the navigator.getcurrentposition call, and would change based on the calculated position if a devices GPS unit was being utilized. Does anyone have suggestions how to implement this with the removeMarker() function? I would guess some sort of conditional where if number of markers = 1, remove marker[0] then addMarker, but I&#39;m not sure how to get this operational. Thanks in advance. Code is below.</div>
<div><br></div><div><div>var markers = new OpenLayers.Layer.Markers(&quot;Markers&quot;);</div><div>var map = new OpenLayers.Map(&#39;simple_geoloc&#39;);</div><div>function init_simple_geo(){</div><div>map.addControl(new OpenLayers.Control.LayerSwitcher());</div>
<div>var mapnik = new OpenLayers.Layer.OSM();</div><div>map.addLayer(mapnik);</div><div>map.setCenter(new OpenLayers.LonLat(-73.98, 40.77).transform(new OpenLayers.Projection(&quot;EPSG:4326&quot;),map.getProjectionObject()),12);</div>
<div>} </div><div><br></div><div><br></div><div>jQuery(window).ready(function(){jQuery(&quot;#btnInit&quot;).click(getLoc);});</div><div>function getLoc(){</div><div>if (Modernizr.geolocation) {</div><div> navigator.geolocation.getCurrentPosition(showMap,handle_error);</div>
<div>} else {</div><div>yqlgeo.get(&#39;visitor&#39;,norm_yql_resp);</div><div>}</div><div>}</div><div><br></div><div><br></div><div>function showMap(position)</div><div>{</div><div>var lonlat = new OpenLayers.LonLat(position.coords.longitude,position.coords.latitude).transform(new OpenLayers.Projection(&quot;EPSG:4326&quot;),map.getProjectionObject());</div>
<div>map.addLayer(markers);</div><div>markers.addMarker(new OpenLayers.Marker(lonlat));</div><div>var bounds = markers.getDataExtent();</div><div>map.zoomToExtent(bounds);</div><div>}</div><div><br></div><div>function handle_error(error) {</div>
<div>switch(error.code){</div><div>case error.PERMISSION_DENIED: alert(&quot;This application reguires you to agree to share your location. Please reload the page to see it work properly. There is a privacy disclaimer at the bottom of this page. This site does not currently record or store these data, and in the future will not record unique user information without informing the user or asking their permission. -Virtual Spatiality&quot;);</div>
<div>break;</div><div>  </div><div>case error.POSITION_UNAVAILABLE: alert(&quot;could not determine position&quot;);</div><div>break;</div><div>  </div><div>case error.TIMEOUT: alert(&quot;timeout retrieving position&quot;);</div>
<div>break;</div><div>  </div><div>default: alert(&quot;unknown error&quot;);</div><div>break;</div><div>}</div><div>}</div><div><br></div><div>function norm_yql_resp(response){</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (response.error) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>var error = {code : 0};</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>handle_error(error);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>var position = {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>coords:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>latitude: response.place.centroid.latitude,</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>longitude: response.place.centroid.longitude</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>},</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>address :</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>city: response.place.locality2.content,</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>region: response.place.admin1.content,</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>country: response.place.country.content</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>};</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>handle_geolocation_query(position);</div><div>}</div></div>