Hi all,<div><br></div><div>In trying to get my little geolocation script to work, I&#39;m stumbling across the following. Can anyone suggest how to modify this script in order to listen to the addMarker event? I realize that this isn&#39;t working because the  markers layer doesn&#39;t load, but I&#39;m not familiar enough with the syntax in order to modify this. Is there a simple event identifier I can pass to the markers.events.register? Full code below.</div>
<div><br></div><div><div>if(! map.getCenter()){</div><div><span class="Apple-tab-span" style="white-space: pre; ">        </span>if(markers)markers.events.register(&#39;loadend&#39;, markers, function(){</div><div>map.zoomToExtent(markers.getDataExtent());}</div>
<div>);</div><div>} else{</div><div>map.setCenter(new OpenLayers.LonLat(-90, 38).transform(new OpenLayers.Projection(&quot;EPSG:4326&quot;),map.getProjectionObject()),12);</div><div>}</div></div><div><br></div><div>Thanks in advance!</div>
<div><br></div><div><br></div><div><br></div><div><div>&lt;!doctype html&gt;</div><div>&lt;html&gt;</div><div>&lt;head&gt;</div><div>&lt;style&gt;</div><div>#map{</div><div>width:400px;</div><div>height:400px;</div><div>}</div>
<div>&lt;/style&gt;</div><div><br></div><div>&lt;/head&gt;</div><div>&lt;body onLoad=&quot;initGIS()&quot;&gt;</div><div>&lt;div id=&quot;map&quot;&gt;&lt;/div&gt;</div><div>&lt;button id=&quot;btnInit&quot; &gt;Find my location&lt;/button&gt;</div>
<div>&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;OpenLayers-2.11-rc1/OpenLayers.js&quot;&gt;&lt;/script&gt;</div><div>&lt;script tyle=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;moderinzr2.js&quot;&gt;&lt;/script&gt;</div>
<div>&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;jquery-1.6.js&quot;&gt;&lt;/script&gt;</div><div>&lt;script src=&quot;<a href="http://www.openstreetmap.org/openlayers/OpenStreetMap.js">http://www.openstreetmap.org/openlayers/OpenStreetMap.js</a>&quot;&gt;&lt;/script&gt;</div>
<div>&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;</div><div>var markers = new OpenLayers.Layer.Markers(&quot;Markers&quot;);</div><div>var map = new OpenLayers.Map(&#39;map&#39;);</div><div>
function initGIS(){</div><div>map.addControl(new OpenLayers.Control.LayerSwitcher());</div><div>var mapnik = new OpenLayers.Layer.OSM();</div><div>map.addLayer(mapnik,markers);</div><div>if(! map.getCenter()){</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(markers)markers.events.register(&#39;loadend&#39;, markers, function(){</div>
<div>map.zoomToExtent(markers.getDataExtent());}</div><div>);</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>//alert(&#39;Lat: &#39; + position.coords.latitude + &#39; &#39; + &#39;Lon: &#39; + position.coords.longitude + &#39; &#39; + &#39;Acc: &#39; + position.coords.accuracy);</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>markers.addMarker(new OpenLayers.Marker(lonlat));</div>
<div>//map.setCenter(new OpenLayers.LonLat(lonlat, 12));</div><div>map.addLayer(markers);</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>&lt;/script&gt;</div><div>&lt;/body&gt;</div><div>&lt;/html&gt;</div></div>